|
|
@@ -67,41 +67,48 @@ module.exports = {
|
|
67
|
67
|
const membershipType = request.query.type
|
|
68
|
68
|
|
|
69
|
69
|
const profileId = request.params.profile_id
|
|
70
|
|
- let groupings = await membershipService.findGroupingsByProfileId(
|
|
|
70
|
+ const groupings = await membershipService.findGroupingsByProfileId(
|
|
71
|
71
|
profileId,
|
|
72
|
72
|
membershipType,
|
|
73
|
73
|
)
|
|
74
|
|
- let memberships = await membershipService.findMemberships(
|
|
75
|
|
- groupings.map(grouping => grouping.grouping_id),
|
|
|
74
|
+ const groupingIds = groupings.map(grouping => grouping.grouping_id)
|
|
|
75
|
+ const memberships = await membershipService.findMemberships(
|
|
|
76
|
+ groupingIds,
|
|
|
77
|
+ )
|
|
|
78
|
+ const profileIds = memberships
|
|
|
79
|
+ .filter(membership => membership.profile_id != profileId)
|
|
|
80
|
+ .map(membership => membership.profile_id)
|
|
|
81
|
+
|
|
|
82
|
+ /** Assemble complete profiles to reference and pass */
|
|
|
83
|
+ const completedProfiles = await profileService.getProfilesFor(
|
|
|
84
|
+ profileIds,
|
|
|
85
|
+ 'participant',
|
|
76
|
86
|
)
|
|
77
|
87
|
|
|
78
|
88
|
/**
|
|
79
|
89
|
* Heavily process the result by storing just a profile_id
|
|
80
|
90
|
* and attach complete profiles
|
|
|
91
|
+ * !: This still assumes only ONE other profile
|
|
|
92
|
+ * TODO: should be refactored to many other profiles
|
|
81
|
93
|
*/
|
|
82
|
|
- let pIds = groupings.reduce((ids, grouping) => {
|
|
83
|
|
- grouping.profiles.forEach(p => {
|
|
84
|
|
- if (p.profile_id == profileId) return
|
|
85
|
|
- ids.push(p.profile_id)
|
|
86
|
|
- grouping.profile = p.profile_id
|
|
87
|
|
- })
|
|
|
94
|
+ const reformattedGroupings = groupings.map(grouping => {
|
|
|
95
|
+ const otherPid = grouping.profiles.find(
|
|
|
96
|
+ p => p.profile_id != profileId,
|
|
|
97
|
+ ).profile_id
|
|
|
98
|
+ grouping.profile = completedProfiles.find(
|
|
|
99
|
+ p => otherPid == p.profile_id,
|
|
|
100
|
+ )
|
|
|
101
|
+ grouping.is_paired = _activeGroupingIds(memberships).includes(
|
|
|
102
|
+ grouping.grouping_id,
|
|
|
103
|
+ )
|
|
88
|
104
|
delete grouping.profiles
|
|
89
|
|
- return ids
|
|
90
|
|
- }, [])
|
|
91
|
|
- /** Assemble complete profiles to reference and pass */
|
|
92
|
|
- const completedProfiles = await profileService.getProfilesFor(
|
|
93
|
|
- pIds,
|
|
94
|
|
- 'participant',
|
|
95
|
|
- )
|
|
|
105
|
+ return grouping
|
|
|
106
|
+ })
|
|
96
|
107
|
|
|
97
|
108
|
/** Grabs revealTags */
|
|
98
|
|
- const profileIdsFromCompletedProfiles = completedProfiles.map(
|
|
99
|
|
- p => p.profile_id,
|
|
100
|
|
- )
|
|
101
|
|
- const groupingIdsFromGroupings = groupings.map(g => g.grouping_id)
|
|
102
|
109
|
const revealTags = await profileService.getTagsFor(
|
|
103
|
|
- profileIdsFromCompletedProfiles,
|
|
104
|
|
- groupingIdsFromGroupings,
|
|
|
110
|
+ profileIds,
|
|
|
111
|
+ groupingIds,
|
|
105
|
112
|
'reveal',
|
|
106
|
113
|
)
|
|
107
|
114
|
|
|
|
@@ -109,30 +116,18 @@ module.exports = {
|
|
109
|
116
|
* removed and replaced with the completedProfile's user information
|
|
110
|
117
|
* Otherwise the completedProfiles remain unchanged
|
|
111
|
118
|
*/
|
|
112
|
|
- const userIdsFromCompletedProfiles = completedProfiles.map(
|
|
113
|
|
- p => p.user_id,
|
|
114
|
|
- )
|
|
115
|
119
|
const user = await userService.findById(
|
|
116
|
|
- userIdsFromCompletedProfiles,
|
|
|
120
|
+ completedProfiles.map(p => p.user_id),
|
|
117
|
121
|
)
|
|
118
|
|
- if (revealTags && user) {
|
|
119
|
|
- for (const t of revealTags) {
|
|
120
|
|
- if (t.tag.tag_description) {
|
|
121
|
|
- completedProfiles[0][t.tag.tag_description] =
|
|
122
|
|
- user[t.tag.tag_description]
|
|
123
|
|
- }
|
|
124
|
|
- }
|
|
125
|
|
- }
|
|
126
|
122
|
|
|
127
|
|
- const reformattedGroupings = groupings.map(g => {
|
|
128
|
|
- completedProfiles.forEach(p => {
|
|
129
|
|
- g.profile = g.profile == p.profile_id ? p : g.profile
|
|
|
123
|
+ // TODO: Refactor this. Is it safe to always use completedProfiles[0]?
|
|
|
124
|
+ if (revealTags && user) {
|
|
|
125
|
+ revealTags.forEach(t => {
|
|
|
126
|
+ if (!t.tag.tag_description) return
|
|
|
127
|
+ completedProfiles[0][t.tag.tag_description] =
|
|
|
128
|
+ user[t.tag.tag_description]
|
|
130
|
129
|
})
|
|
131
|
|
- g.is_paired = _activeGroupingIds(memberships).includes(
|
|
132
|
|
- g.grouping_id,
|
|
133
|
|
- )
|
|
134
|
|
- return g
|
|
135
|
|
- })
|
|
|
130
|
+ }
|
|
136
|
131
|
|
|
137
|
132
|
try {
|
|
138
|
133
|
return {
|