|
|
@@ -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(
|