Browse Source

:construction: first attempt at setting default profile values for hiding

tags/0.0.3^2
juancarbajal98 3 years ago
parent
commit
eb2eaaae8d
1 changed files with 29 additions and 1 deletions
  1. 29
    1
      backend/lib/services/profile/index.js

+ 29
- 1
backend/lib/services/profile/index.js View File

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

Loading…
Cancel
Save