Selaa lähdekoodia

:recycle: Continuing with reveal refactor

tags/0.0.3^2
tomit4 3 vuotta sitten
vanhempi
commit
4719b774df

+ 30
- 23
backend/lib/routes/membership/active.js Näytä tiedosto

@@ -62,7 +62,7 @@ module.exports = {
62 62
         auth: false,
63 63
         cors: true,
64 64
         handler: async function (request, h) {
65
-            const { membershipService, profileService } =
65
+            const { membershipService, profileService, userService } =
66 66
                 request.server.services()
67 67
             const membershipType = request.query.type
68 68
 
@@ -95,6 +95,34 @@ module.exports = {
95 95
                 'participant',
96 96
                 false,
97 97
             )
98
+
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)
105
+                        }
106
+                    }
107
+                })
108
+            })
109
+
110
+            const getRevealInfo = async () => {
111
+                const profilesWithRevealed = []
112
+                for (const profile of completedProfiles) {
113
+                    const userInfo = await userService.findById(profile.user_id)
114
+                    for (const tag of revealTags) {
115
+                        profile[tag.tag_description] = userInfo[tag.tag_description]
116
+                    }
117
+                    profilesWithRevealed.push(profile)
118
+                }
119
+                return profilesWithRevealed
120
+            }
121
+
122
+            const revealedInfo = await getRevealInfo()
123
+            console.log('revealedInfo :=>', revealedInfo)
124
+            // if revealTags.length, return revealInfo, otherwise return completeProfiles...
125
+
98 126
             const reformattedGroupings = groupings.map(g => {
99 127
                 completedProfiles.forEach(p => {
100 128
                     g.profile = g.profile == p.profile_id ? p : g.profile
@@ -102,30 +130,9 @@ module.exports = {
102 130
                 g.is_paired = _activeGroupingIds(memberships).includes(
103 131
                     g.grouping_id,
104 132
                 )
105
-
106
-                const defaultValues = {
107
-                    user_name: g.profile.user_info.user_name,
108
-                    user_email: g.profile.user_info.user_email
109
-                }
110
-
111
-                // NOTE: better...at least it's not globally shown on the home page...
112
-                // but we can't rely on reveal for this, it has to be in this grouping in particular
113
-                if (g.profile.reveal.length) {
114
-                    console.log('g.profile.reveal :=>', g.profile.reveal)
115
-                    for (let [attribute, defaultVal] of Object.entries(defaultValues)) {
116
-                        const typeOfReveal = typeof g.profile.reveal.find(tag =>
117
-                            tag.tag_description === attribute)
118
-                        if (typeOfReveal !== 'undefined') {
119
-                            g.profile[attribute] = defaultVal
120
-                        }
121
-                    }
122
-                }
123
-
124
-                // NOTE: delete profile.user_info for privacy
125
-                delete g.profile.user_info
126 133
                 return g
127 134
             })
128
-            console.log('reformattedGroupings :=>', reformattedGroupings[0].profile.user_name)
135
+
129 136
             try {
130 137
                 return {
131 138
                     ok: true,

+ 0
- 1
backend/lib/schemas/profiles.js Näytä tiedosto

@@ -10,7 +10,6 @@ const singleProfile = Joi.object({
10 10
     user_id: Joi.number(),
11 11
     user_name: Joi.string(),
12 12
     user_email: Joi.string(),
13
-    user_info: Joi.any(),
14 13
     responses: surveyResponseSchema.list,
15 14
     reveal: Joi.array().items(),
16 15
     tags: tagSchema.list,

+ 2
- 2
backend/lib/services/profile/profiler.js Näytä tiedosto

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

+ 0
- 1
frontend/src/entities/profile/profile.schema.js Näytä tiedosto

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

Loading…
Peruuta
Tallenna