Преглед изворни кода

:bug: Moved hide logic into CompleteProfile constructor

tags/0.0.3^2
tomit4 пре 3 година
родитељ
комит
6d931e09b7
2 измењених фајлова са 14 додато и 37 уклоњено
  1. 0
    37
      backend/lib/services/profile/index.js
  2. 14
    0
      backend/lib/services/profile/profiler.js

+ 0
- 37
backend/lib/services/profile/index.js Прегледај датотеку

@@ -63,10 +63,7 @@ module.exports = class ProfileService extends Schmervice.Service {
63 63
             tag => this.tagLookup[tag.tag_id],
64 64
         )
65 65
         const complete = new profiler.CompleteProfile(matchingProfile, true)
66
-        // TODO: Refactor to use this.setDefaults(), currently does not play
67
-        // nice with reveal functionality
68 66
         return complete
69
-        // return this.setDefaults(complete)
70 67
     }
71 68
 
72 69
     async getCompleteProfilesFor(userId, type) {
@@ -228,40 +225,6 @@ module.exports = class ProfileService extends Schmervice.Service {
228 225
         return allResponses
229 226
     }
230 227
 
231
-    /**
232
-     * Sets default profile attributes
233
-     * @param {object} complete
234
-     * @returns {object} updated profile
235
-     */
236
-    setDefaults(complete) {
237
-        let defaultValues = {
238
-            user_email: 'hidden@email.com',
239
-            user_name: 'Hidden Name',
240
-        }
241
-
242
-        let defaultProfile = {
243
-            ...complete,
244
-            user_email: defaultValues.user_email,
245
-            user_name: defaultValues.user_name,
246
-        }
247
-        console.log('---')
248
-        console.log('defaultProfile: ', defaultProfile.user_email)
249
-        if (!complete.reveal.length) return defaultProfile // nothing to reveal
250
-
251
-        // swap out values of keys that are not found as complete.reveal.tag.tag_description values
252
-        for (let [attribute, defaultVal] of Object.entries(defaultValues)) {
253
-            if (
254
-                typeof complete.reveal.find(
255
-                    tag => tag.tag_description == attribute,
256
-                ) == 'undefined'
257
-            )
258
-                complete[attribute] = defaultVal
259
-        }
260
-        console.log('complete: ', complete.user_email)
261
-
262
-        return complete
263
-    }
264
-
265 228
     /**
266 229
      * Delete a profile
267 230
      * @param {number} userId

+ 14
- 0
backend/lib/services/profile/profiler.js Прегледај датотеку

@@ -27,6 +27,20 @@ class CompleteProfile {
27 27
         // TODO: and include for certain profiles
28 28
 
29 29
         this.reveal = profile.tags.filter(t => t.tag_category == 'reveal')
30
+        // Hides values until revealed
31
+        const defaultValues = {
32
+            user_name: 'hidden_name',
33
+            user_email: 'hidden@email.com',
34
+        }
35
+        // BUG: If user reveals EITHER name or email, BOTH get revealed together...
36
+        if (!this.reveal.length) {
37
+            for (let [attribute, defaultVal] of Object.entries(defaultValues)) {
38
+                const typeOfReveal = this.reveal.find(tag => tag.tag_description === attribute)
39
+                if (typeOfReveal === undefined) {
40
+                    this[attribute] = defaultVal
41
+                }
42
+            }
43
+        }
30 44
         // TODO: filter these correctly
31 45
         if (profile?.responses?.length && includeResponses) {
32 46
             // [] of all "profile" responses

Loading…
Откажи
Сачувај