Pārlūkot izejas kodu

:recycle: Continuing with reveal refactor

tags/0.0.3^2
tomit4 3 gadus atpakaļ
vecāks
revīzija
4719b774df

+ 30
- 23
backend/lib/routes/membership/active.js Parādīt failu

62
         auth: false,
62
         auth: false,
63
         cors: true,
63
         cors: true,
64
         handler: async function (request, h) {
64
         handler: async function (request, h) {
65
-            const { membershipService, profileService } =
65
+            const { membershipService, profileService, userService } =
66
                 request.server.services()
66
                 request.server.services()
67
             const membershipType = request.query.type
67
             const membershipType = request.query.type
68
 
68
 
95
                 'participant',
95
                 'participant',
96
                 false,
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
             const reformattedGroupings = groupings.map(g => {
126
             const reformattedGroupings = groupings.map(g => {
99
                 completedProfiles.forEach(p => {
127
                 completedProfiles.forEach(p => {
100
                     g.profile = g.profile == p.profile_id ? p : g.profile
128
                     g.profile = g.profile == p.profile_id ? p : g.profile
102
                 g.is_paired = _activeGroupingIds(memberships).includes(
130
                 g.is_paired = _activeGroupingIds(memberships).includes(
103
                     g.grouping_id,
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
                 return g
133
                 return g
127
             })
134
             })
128
-            console.log('reformattedGroupings :=>', reformattedGroupings[0].profile.user_name)
135
+
129
             try {
136
             try {
130
                 return {
137
                 return {
131
                     ok: true,
138
                     ok: true,

+ 0
- 1
backend/lib/schemas/profiles.js Parādīt failu

10
     user_id: Joi.number(),
10
     user_id: Joi.number(),
11
     user_name: Joi.string(),
11
     user_name: Joi.string(),
12
     user_email: Joi.string(),
12
     user_email: Joi.string(),
13
-    user_info: Joi.any(),
14
     responses: surveyResponseSchema.list,
13
     responses: surveyResponseSchema.list,
15
     reveal: Joi.array().items(),
14
     reveal: Joi.array().items(),
16
     tags: tagSchema.list,
15
     tags: tagSchema.list,

+ 2
- 2
backend/lib/services/profile/profiler.js Parādīt failu

13
         this.user_email = 'hidden@email.com'
13
         this.user_email = 'hidden@email.com'
14
         this.responses = []
14
         this.responses = []
15
         this.user_type = type
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
         // TODO: generalize this for multiple images, and languages
18
         // TODO: generalize this for multiple images, and languages
18
         this.profile_description = ''
19
         this.profile_description = ''
19
         this.profile_media = []
20
         this.profile_media = []
20
         this.profile_languages = []
21
         this.profile_languages = []
21
         this.profile_prefs = {}
22
         this.profile_prefs = {}
22
-        this.user_info = profile.user
23
 
23
 
24
         // TODO: Use reveal tags to add or remove information from profile!
24
         // TODO: Use reveal tags to add or remove information from profile!
25
         // TODO: ---
25
         // TODO: ---

+ 0
- 1
frontend/src/entities/profile/profile.schema.js Parādīt failu

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
-        user_info: Joi.any(),
31
         profile_id: Joi.number(),
30
         profile_id: Joi.number(),
32
         profile_description: Joi.string().allow(null, ''),
31
         profile_description: Joi.string().allow(null, ''),
33
         profile_media: Joi.array().items(Joi.string()),
32
         profile_media: Joi.array().items(Joi.string()),

Notiek ielāde…
Atcelt
Saglabāt