Explorar el Código

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

tags/0.0.3^2
tomit4 hace 3 años
padre
commit
78f0fcea98

+ 39
- 19
backend/lib/routes/membership/active.js Ver fichero

75
                 groupings.map(grouping => grouping.grouping_id),
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
              * Heavily process the result by storing just a profile_id
83
              * Heavily process the result by storing just a profile_id
80
              * and attach complete profiles
84
              * and attach complete profiles
81
              */
85
              */
86
+            // NOTE: only returns the pId for the target
82
             let pIds = groupings.reduce((ids, grouping) => {
87
             let pIds = groupings.reduce((ids, grouping) => {
83
                 grouping.profiles.forEach(p => {
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
                     ids.push(p.profile_id)
92
                     ids.push(p.profile_id)
86
                     grouping.profile = p.profile_id
93
                     grouping.profile = p.profile_id
87
                 })
94
                 })
88
                 delete grouping.profiles
95
                 delete grouping.profiles
89
                 return ids
96
                 return ids
90
             }, [])
97
             }, [])
91
-
98
+            console.log('pIds :=>', pIds) // only returns single array of target id
92
             /** Assemble complete profiles to reference and pass */
99
             /** Assemble complete profiles to reference and pass */
93
             const completedProfiles = await profileService.getProfilesFor(
100
             const completedProfiles = await profileService.getProfilesFor(
94
                 pIds,
101
                 pIds,
96
                 false,
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
             const getRevealInfo = async () => {
122
             const getRevealInfo = async () => {
111
                 const profilesWithRevealed = []
123
                 const profilesWithRevealed = []
112
                 for (const profile of completedProfiles) {
124
                 for (const profile of completedProfiles) {
113
                     const userInfo = await userService.findById(profile.user_id)
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
             const reformattedGroupings = groupings.map(g => {
146
             const reformattedGroupings = groupings.map(g => {
127
-                completedProfiles.forEach(p => {
147
+                completedProfilesWithRevealedInfo.forEach(p => {
128
                     g.profile = g.profile == p.profile_id ? p : g.profile
148
                     g.profile = g.profile == p.profile_id ? p : g.profile
129
                 })
149
                 })
130
                 g.is_paired = _activeGroupingIds(memberships).includes(
150
                 g.is_paired = _activeGroupingIds(memberships).includes(
132
                 )
152
                 )
133
                 return g
153
                 return g
134
             })
154
             })
135
-
155
+            console.log('reformattedGroupings :=>', reformattedGroupings)
136
             try {
156
             try {
137
                 return {
157
                 return {
138
                     ok: true,
158
                     ok: true,

+ 3
- 3
backend/lib/routes/membership/reveal.js Ver fichero

31
         auth: false,
31
         auth: false,
32
         cors: true,
32
         cors: true,
33
         handler: async function (request, h) {
33
         handler: async function (request, h) {
34
-            const { membershipService, profileService } =
34
+            const { membershipService, profileService, userService } =
35
                 request.server.services()
35
                 request.server.services()
36
             const grouping_id = request.params.grouping_id
36
             const grouping_id = request.params.grouping_id
37
             const { profile_id, tag_id } = request.query
37
             const { profile_id, tag_id } = request.query
72
                 }
72
                 }
73
 
73
 
74
                 const tag_description = returnedTag().tag.tag_description
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
                 idsInGroup.forEach(profile_id => {
78
                 idsInGroup.forEach(profile_id => {
79
                     request.server.methods.notify(
79
                     request.server.methods.notify(

+ 2
- 0
backend/lib/schemas/profiles.js Ver fichero

13
     responses: surveyResponseSchema.list,
13
     responses: surveyResponseSchema.list,
14
     reveal: Joi.array().items(),
14
     reveal: Joi.array().items(),
15
     tags: tagSchema.list,
15
     tags: tagSchema.list,
16
+    image: Joi.any(),
17
+    blurb: Joi.any(),
16
     user_type: Joi.any(),
18
     user_type: Joi.any(),
17
     user: userSchema.single,
19
     user: userSchema.single,
18
     profile_description: Joi.string().allow(null, ''),
20
     profile_description: Joi.string().allow(null, ''),

+ 3
- 1
backend/lib/services/profile/profiler.js Ver fichero

14
         this.responses = []
14
         this.responses = []
15
         this.user_type = type
15
         this.user_type = type
16
         // NOTE: just have all the tags in one place
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
         // TODO: generalize this for multiple images, and languages
18
         // TODO: generalize this for multiple images, and languages
19
         this.profile_description = ''
19
         this.profile_description = ''
20
         this.profile_media = []
20
         this.profile_media = []
21
         this.profile_languages = []
21
         this.profile_languages = []
22
         this.profile_prefs = {}
22
         this.profile_prefs = {}
23
+        this.image = ''
24
+        this.blurb = ''
23
 
25
 
24
         // TODO: Use reveal tags to add or remove information from profile!
26
         // TODO: Use reveal tags to add or remove information from profile!
25
         // TODO: ---
27
         // TODO: ---

+ 2
- 0
frontend/src/entities/profile/profile.schema.js Ver fichero

27
         user_name: Joi.string(),
27
         user_name: Joi.string(),
28
         user_id: Joi.number(),
28
         user_id: Joi.number(),
29
         user_email: Joi.string(),
29
         user_email: Joi.string(),
30
+        image: Joi.any(),
31
+        blurb: Joi.any(),
30
         profile_id: Joi.number(),
32
         profile_id: Joi.number(),
31
         profile_description: Joi.string().allow(null, ''),
33
         profile_description: Joi.string().allow(null, ''),
32
         profile_media: Joi.array().items(Joi.string()),
34
         profile_media: Joi.array().items(Joi.string()),

+ 0
- 1
frontend/src/services/notification.service.js Ver fichero

53
                 tag_category: "reveal",
53
                 tag_category: "reveal",
54
                 tag_description: parsed.description,
54
                 tag_description: parsed.description,
55
                 tag_id: parsed.tag,
55
                 tag_id: parsed.tag,
56
-                for_profile_id: foundGrouping.profile.profile_id
57
             }
56
             }
58
             const target_desc = parsed.description
57
             const target_desc = parsed.description
59
             tagFromNotification[target_desc] = parsed.revealed_info
58
             tagFromNotification[target_desc] = parsed.revealed_info

Loading…
Cancelar
Guardar