Ver código fonte

:recycle: Major refactor almost complete, lesser bugs to address

tags/0.0.3^2
tomit4 3 anos atrás
pai
commit
91ebfee76a

+ 38
- 36
backend/lib/routes/membership/active.js Ver arquivo

@@ -89,52 +89,54 @@ module.exports = {
89 89
                 return ids
90 90
             }, [])
91 91
             /** Assemble complete profiles to reference and pass */
92
-            const completedProfiles = await profileService.getProfilesFor(
92
+            let completedProfiles = await profileService.getProfilesFor(
93 93
                 pIds,
94 94
                 'participant',
95 95
                 false,
96 96
             )
97
-            // NOTE: Doesn't rely on profile reveal field to get reveal tags
98
-            const getGroupingRevealTags = async () => {
99
-                const groupingRevealTags = []
100
-                for (const grouping of groupings) {
97
+
98
+            /** Grabs the reveal tags for the target profile */
99
+            const revealTags = await groupings.reduce(
100
+                async (revealTags, grouping) => {
101 101
                     for (const profile of completedProfiles) {
102
-                        const revealTags = await profileService.getTagsFor(profile.profile_id, grouping.grouping_id, 'reveal')
103
-                        if (revealTags.length) {
104
-                            groupingRevealTags.push(revealTags)
105
-                        }
102
+                        revealTags = await profileService.
103
+                            getTagsFor(
104
+                                profile.profile_id,
105
+                                grouping.grouping_id,
106
+                                'reveal')
107
+                        if (revealTags.length) return revealTags
106 108
                     }
107
-                }
108
-                return groupingRevealTags
109
-            }
109
+                }, [])
110 110
 
111
-            const revealTags = await getGroupingRevealTags()
112
-            // TODO: Refactor, triple for of loop...
113
-            const getRevealInfo = async () => {
114
-                const profilesWithRevealed = []
115
-                for (const profile of completedProfiles) {
116
-                    const userInfo = await userService.findById(profile.user_id)
117
-                    if (userInfo && revealTags.length) {
118
-                        for (const tags of revealTags) {
119
-                            for (const tag of tags) {
120
-                                if (tag.tag.tag_description) {
121
-                                    profile[tag.tag.tag_description] = userInfo[tag.tag.tag_description]
122
-                                }
123
-                            }
124
-                        }
125
-                        profilesWithRevealed.push(profile)
111
+            /** If the revealTags exist, the completedProfile's hidden info is
112
+            * removed and replaced with the completedProfile's user information
113
+            * Otherwise the completedProfiles remain unchanged
114
+             */
115
+            completedProfiles = await completedProfiles.reduce(
116
+                async (profilesWithRevealed, profile) => {
117
+                    if (!revealTags) return completedProfiles
118
+                    const user = await userService.findById(profile.user_id)
119
+                    if (user) {
120
+                        for (const t of revealTags)
121
+                            if (t.tag.tag_description)
122
+                                profile[t.tag.tag_description] = 
123
+                                    user[t.tag.tag_description]
124
+                        profilesWithRevealed = profile
125
+                        return profilesWithRevealed = 
126
+                            profilesWithRevealed.length ? 
127
+                                profilesWithRevealed : 
128
+                                completedProfiles
129
+                    } else {
130
+                        // TODO: consider removing, throwIfNotFound used in findById
131
+                        console.error(
132
+                            '[User Service Error] no user id found for profile id >> ', 
133
+                            profile.profile_id)
134
+                        return completedProfiles
126 135
                     }
127
-                }
128
-                if (profilesWithRevealed.length)
129
-                    return profilesWithRevealed
130
-                else
131
-                    return completedProfiles
132
-            }
133
-
134
-            const completedProfilesWithRevealedInfo = await getRevealInfo()
136
+                }, [])
135 137
 
136 138
             const reformattedGroupings = groupings.map(g => {
137
-                completedProfilesWithRevealedInfo.forEach(p => {
139
+                completedProfiles.forEach(p => {
138 140
                     g.profile = g.profile == p.profile_id ? p : g.profile
139 141
                 })
140 142
                 g.is_paired = _activeGroupingIds(memberships).includes(

+ 4
- 4
frontend/src/views/ChatView.vue Ver arquivo

@@ -16,15 +16,15 @@ main.view--chat
16 16
                 // TODO: Remove later, only for testing
17 17
                 button(@click='checkData()') check data
18 18
             span(v-if="grouping.revealed[profile.id.value]")
19
-                p you revealed: 
20
-                ul(v-for="reveal in grouping.revealed[profile.id.value]")
19
+                p you revealed:
20
+                ul(v-for="reveal in [...new Set(grouping.revealed[profile.id.value])]")
21 21
                     li {{ reveal.description }}
22 22
             span(v-if="grouping.revealed[target.profile_id]")
23 23
                 p they revealed:
24 24
                 ul(v-for="reveal in grouping.revealed[target.profile_id]")
25 25
                     li {{ reveal.description }}: {{ target[reveal.description] }}
26
-            span(v-else-if="grouping.revealedFromNotification.length")
27
-                p they revealed:
26
+            span(v-if="grouping.revealedFromNotification.length")
27
+                p recently revealed:
28 28
                 ul(v-for="revealed in grouping.revealedFromNotification")
29 29
                     li(v-if="revealed[revealed.tag_description] !== profile._profile[revealed.tag_description]") {{ revealed.tag_description }}: {{ revealed[revealed.tag_description] }}
30 30
 

Carregando…
Cancelar
Salvar