Browse Source

:recycle: Continuing refactoring of hidden, almost there...?

tags/0.0.3^2
tomit4 3 years ago
parent
commit
78f0fcea98

+ 39
- 19
backend/lib/routes/membership/active.js View File

@@ -75,20 +75,27 @@ module.exports = {
75 75
                 groupings.map(grouping => grouping.grouping_id),
76 76
             )
77 77
 
78
+            // NOTE: Current implementation works okay, it only reveals the targetID's
79
+            // hidden info on the page currently, it does NOT reveal OUR OWN information
80
+            // to ourselves when revealed
81
+
78 82
             /**
79 83
              * Heavily process the result by storing just a profile_id
80 84
              * and attach complete profiles
81 85
              */
86
+            // NOTE: only returns the pId for the target
82 87
             let pIds = groupings.reduce((ids, grouping) => {
83 88
                 grouping.profiles.forEach(p => {
84
-                    if (p.profile_id == profileId) return
89
+                    // you'd think to comment out here, but it still only returns CompleteProfile of target
90
+                    // pIds would be both currentProfile id and target id though
91
+                    if (p.profile_id == profileId) return 
85 92
                     ids.push(p.profile_id)
86 93
                     grouping.profile = p.profile_id
87 94
                 })
88 95
                 delete grouping.profiles
89 96
                 return ids
90 97
             }, [])
91
-
98
+            console.log('pIds :=>', pIds) // only returns single array of target id
92 99
             /** Assemble complete profiles to reference and pass */
93 100
             const completedProfiles = await profileService.getProfilesFor(
94 101
                 pIds,
@@ -96,35 +103,48 @@ module.exports = {
96 103
                 false,
97 104
             )
98 105
 
99
-            const revealTags = []
100
-            completedProfiles.forEach(p => {
101
-                p.tags.forEach(t => {
102
-                    if (t.tag_category === 'reveal') {
103
-                        if (t.tag_description === 'user_email' || t.tag_description === 'user_name') {
104
-                            revealTags.push(t)
106
+            // NOTE: Doesn't rely on profile reveal field to get reveal tags
107
+            const getGroupingRevealTags = async () => {
108
+                const groupingRevealTags = []
109
+                for (const grouping of groupings) {
110
+                    for (const profile of completedProfiles) {
111
+                        const revealTags = await profileService.getTagsFor(profile.profile_id, grouping.grouping_id, 'reveal')
112
+                        if (revealTags.length) {
113
+                            groupingRevealTags.push(revealTags)
105 114
                         }
106 115
                     }
107
-                })
108
-            })
116
+                }
117
+                return groupingRevealTags
118
+            }
109 119
 
120
+            const revealTags = await getGroupingRevealTags()
121
+            // TODO: Refactor, triple for of loop...
110 122
             const getRevealInfo = async () => {
111 123
                 const profilesWithRevealed = []
112 124
                 for (const profile of completedProfiles) {
113 125
                     const userInfo = await userService.findById(profile.user_id)
114
-                    for (const tag of revealTags) {
115
-                        profile[tag.tag_description] = userInfo[tag.tag_description]
126
+                    if (userInfo && revealTags.length) {
127
+                        for (const tags of revealTags) {
128
+                            for (const tag of tags) {
129
+                                if (tag.tag.tag_description) {
130
+                                    profile[tag.tag.tag_description] = userInfo[tag.tag.tag_description]
131
+                                }
132
+                            }
133
+                        }
134
+                        profilesWithRevealed.push(profile)
116 135
                     }
117
-                    profilesWithRevealed.push(profile)
118 136
                 }
119
-                return profilesWithRevealed
137
+                if (profilesWithRevealed.length)
138
+                    return profilesWithRevealed
139
+                else
140
+                    return completedProfiles
120 141
             }
121 142
 
122
-            const revealedInfo = await getRevealInfo()
123
-            console.log('revealedInfo :=>', revealedInfo)
124
-            // if revealTags.length, return revealInfo, otherwise return completeProfiles...
143
+            const completedProfilesWithRevealedInfo = await getRevealInfo()
125 144
 
145
+            // ISSUE: renders target ID but not currentProfileID in ChatView.vue
126 146
             const reformattedGroupings = groupings.map(g => {
127
-                completedProfiles.forEach(p => {
147
+                completedProfilesWithRevealedInfo.forEach(p => {
128 148
                     g.profile = g.profile == p.profile_id ? p : g.profile
129 149
                 })
130 150
                 g.is_paired = _activeGroupingIds(memberships).includes(
@@ -132,7 +152,7 @@ module.exports = {
132 152
                 )
133 153
                 return g
134 154
             })
135
-
155
+            console.log('reformattedGroupings :=>', reformattedGroupings)
136 156
             try {
137 157
                 return {
138 158
                     ok: true,

+ 3
- 3
backend/lib/routes/membership/reveal.js View File

@@ -31,7 +31,7 @@ module.exports = {
31 31
         auth: false,
32 32
         cors: true,
33 33
         handler: async function (request, h) {
34
-            const { membershipService, profileService } =
34
+            const { membershipService, profileService, userService } =
35 35
                 request.server.services()
36 36
             const grouping_id = request.params.grouping_id
37 37
             const { profile_id, tag_id } = request.query
@@ -72,8 +72,8 @@ module.exports = {
72 72
                 }
73 73
 
74 74
                 const tag_description = returnedTag().tag.tag_description
75
-                // TODO: Refactor completeProfile[0]... code smell
76
-                const revealInfo = completeProfile[0][tag_description]
75
+                const userInfo = await userService.findById(completeProfile[0].user_id)
76
+                const revealInfo = userInfo[tag_description]
77 77
 
78 78
                 idsInGroup.forEach(profile_id => {
79 79
                     request.server.methods.notify(

+ 2
- 0
backend/lib/schemas/profiles.js View File

@@ -13,6 +13,8 @@ const singleProfile = Joi.object({
13 13
     responses: surveyResponseSchema.list,
14 14
     reveal: Joi.array().items(),
15 15
     tags: tagSchema.list,
16
+    image: Joi.any(),
17
+    blurb: Joi.any(),
16 18
     user_type: Joi.any(),
17 19
     user: userSchema.single,
18 20
     profile_description: Joi.string().allow(null, ''),

+ 3
- 1
backend/lib/services/profile/profiler.js View File

@@ -14,12 +14,14 @@ class CompleteProfile {
14 14
         this.responses = []
15 15
         this.user_type = type
16 16
         // NOTE: just have all the tags in one place
17
-        this.tags = profile.tags
17
+        this.tags = profile.tags.filter(t => t.tag_category !== 'reveal')
18 18
         // TODO: generalize this for multiple images, and languages
19 19
         this.profile_description = ''
20 20
         this.profile_media = []
21 21
         this.profile_languages = []
22 22
         this.profile_prefs = {}
23
+        this.image = ''
24
+        this.blurb = ''
23 25
 
24 26
         // TODO: Use reveal tags to add or remove information from profile!
25 27
         // TODO: ---

+ 2
- 0
frontend/src/entities/profile/profile.schema.js View File

@@ -27,6 +27,8 @@ const profileSchema = {
27 27
         user_name: Joi.string(),
28 28
         user_id: Joi.number(),
29 29
         user_email: Joi.string(),
30
+        image: Joi.any(),
31
+        blurb: Joi.any(),
30 32
         profile_id: Joi.number(),
31 33
         profile_description: Joi.string().allow(null, ''),
32 34
         profile_media: Joi.array().items(Joi.string()),

+ 0
- 1
frontend/src/services/notification.service.js View File

@@ -53,7 +53,6 @@ class StonkAlert extends Toaster {
53 53
                 tag_category: "reveal",
54 54
                 tag_description: parsed.description,
55 55
                 tag_id: parsed.tag,
56
-                for_profile_id: foundGrouping.profile.profile_id
57 56
             }
58 57
             const target_desc = parsed.description
59 58
             tagFromNotification[target_desc] = parsed.revealed_info

Loading…
Cancel
Save