Przeglądaj źródła

Merge branch 'hide-profile-info' of fyindr/siimee into dev

tags/0.0.3^2
maeda 3 lat temu
rodzic
commit
646c223461

+ 1
- 1
backend/db/data-generator/config.json Wyświetl plik

@@ -2,7 +2,7 @@
2 2
     "mockOutputPath": "./db/generated",
3 3
     "magic": 1000,
4 4
     "total": 100,
5
-    "ignore": [45],
5
+    "ignore": [],
6 6
     "batchSize": 10,
7 7
     "percentageOfSeekers": 90,
8 8
     "scoreVals": [1, 2, 3, 4, 5, 6, 7],

+ 1
- 1
backend/db/data-generator/mock.js Wyświetl plik

@@ -114,7 +114,7 @@ module.exports = {
114 114
             tag_association_id: 5,
115 115
             profile_id: 45,
116 116
             grouping_id: 2,
117
-            tag_id: 4,
117
+            tag_id: 8,
118 118
             is_deleted: false,
119 119
         },
120 120
         {

+ 50
- 17
backend/lib/services/profile/index.js Wyświetl plik

@@ -4,7 +4,6 @@ const config = require('../../../db/data-generator/config.json')
4 4
 const profiler = require('./profiler')
5 5
 const scoring = require('./scorer')
6 6
 const zipcoder = require('./zipcoder')
7
-const tagger = require('./tagger')
8 7
 
9 8
 module.exports = class ProfileService extends Schmervice.Service {
10 9
     constructor(...args) {
@@ -24,15 +23,14 @@ module.exports = class ProfileService extends Schmervice.Service {
24 23
         }
25 24
     }
26 25
     async _setTagLookup() {
27
-        if (!Object.keys(this.tagLookup).length) {
28
-            const { Tag } = this.server.models()
29
-            const allTagDescriptions = await Tag.query()
30
-            allTagDescriptions.forEach(desc => {
31
-                if (desc.is_active) {
32
-                    this.tagLookup[desc.tag_id] = desc
33
-                }
34
-            })
35
-        }
26
+        /** Grab tag descriptions if they do NOT exist: Needed once per app load */
27
+        if (Object.keys(this.tagLookup).length) return
28
+        const { Tag } = this.server.models()
29
+        const allTagDescriptions = await Tag.query()
30
+        allTagDescriptions.forEach(desc => {
31
+            if (!desc.is_active) return
32
+            this.tagLookup[desc.tag_id] = desc
33
+        })
36 34
     }
37 35
     /**
38 36
      * Internal method to get list of profile_ids for this user
@@ -55,16 +53,17 @@ module.exports = class ProfileService extends Schmervice.Service {
55 53
     async getProfile(profileId) {
56 54
         const { Profile } = this.server.models()
57 55
         await this._setTagLookup()
58
-
59 56
         const matchingProfile = await Profile.query()
60 57
             .where('profile_id', profileId)
61 58
             .first()
62 59
             .withGraphFetched('tags')
63 60
             .withGraphFetched('responses')
64 61
             .withGraphFetched('user')
65
-        tagger.setProfileTags(matchingProfile, matchingProfile, this.tagLookup)
62
+        matchingProfile.tags = matchingProfile.tags.map(
63
+            tag => this.tagLookup[tag.tag_id],
64
+        )
66 65
         const complete = new profiler.CompleteProfile(matchingProfile, true)
67
-        return complete
66
+        return this.setDefaults(complete)
68 67
     }
69 68
 
70 69
     async getCompleteProfilesFor(userId, type) {
@@ -81,7 +80,7 @@ module.exports = class ProfileService extends Schmervice.Service {
81 80
             // so without this, we get undefined user_name
82 81
             .withGraphFetched('user')
83 82
 
84
-        return profiler.makeCompleteProfilesFromProfile(
83
+        return profiler.makeCompleteFromProfileEntries(
85 84
             profilesEntries,
86 85
             type,
87 86
             this.tagLookup,
@@ -103,7 +102,7 @@ module.exports = class ProfileService extends Schmervice.Service {
103 102
         // taking the info from profilesEntries
104 103
         // to repack into completeProfiles
105 104
         // in same order as profileIdArray
106
-        return profiler.makeCompleteProfiles(
105
+        return profiler.makeOrderedCompleteProfiles(
107 106
             profileIdArray,
108 107
             profilesEntries,
109 108
             type,
@@ -226,6 +225,40 @@ module.exports = class ProfileService extends Schmervice.Service {
226 225
         return allResponses
227 226
     }
228 227
 
228
+    /**
229
+     * Sets default profile attributes
230
+     * @param {object} complete
231
+     * @returns {object} updated profile
232
+     */
233
+    setDefaults(complete) {
234
+        let defaultValues = {
235
+            user_email: 'hidden@email.com',
236
+            user_name: 'Hidden Name',
237
+        }
238
+
239
+        let defaultProfile = {
240
+            ...complete,
241
+            user_email: defaultValues.user_email,
242
+            user_name: defaultValues.user_name,
243
+        }
244
+        console.log('---')
245
+        console.log('defaultProfile: ', defaultProfile.user_email)
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 (
251
+                typeof complete.reveal.find(
252
+                    tag => tag.tag_description == attribute,
253
+                ) == 'undefined'
254
+            )
255
+                complete[attribute] = defaultVal
256
+        }
257
+        console.log('complete: ', complete.user_email)
258
+
259
+        return complete
260
+    }
261
+
229 262
     /**
230 263
      * Delete a profile
231 264
      * @param {number} userId
@@ -356,8 +389,8 @@ module.exports = class ProfileService extends Schmervice.Service {
356 389
         await this._setTagLookup()
357 390
         let associations = groupingId
358 391
             ? await TagAssociation.query()
359
-                .where('grouping_id', groupingId)
360
-                .andWhere('profile_id', profileId)
392
+                  .where('grouping_id', groupingId)
393
+                  .andWhere('profile_id', profileId)
361 394
             : await TagAssociation.query().andWhere('profile_id', profileId)
362 395
         return associations
363 396
             .map(assoc => ({

+ 26
- 31
backend/lib/services/profile/profiler.js Wyświetl plik

@@ -1,5 +1,4 @@
1 1
 const config = require('../../../db/data-generator/config.json')
2
-const tagger = require('./tagger')
3 2
 
4 3
 /**
5 4
  * Class to hold our retrieved profile information
@@ -27,7 +26,7 @@ class CompleteProfile {
27 26
         // TODO: Use reveal tags to rebuild profile based on group/membership
28 27
         // TODO: and include for certain profiles
29 28
 
30
-        this.reveal = profile.tags.filter(t => t.category == 'reveal')
29
+        this.reveal = profile.tags.filter(t => t.tag_category == 'reveal')
31 30
         // TODO: filter these correctly
32 31
         if (profile?.responses?.length && includeResponses) {
33 32
             // [] of all "profile" responses
@@ -44,13 +43,13 @@ class CompleteProfile {
44 43
             ]
45 44
             const prefsKeys = config.prefKeys
46 45
             prefs.forEach((pref, i) => {
47
-                this.profile_prefs[pref] = this.responses.filter(
46
+                this.profile_prefs[pref] = this.responses.find(
48 47
                     r => r.response_key_id === prefsKeys[i],
49
-                )[0]
48
+                )
50 49
             })
51
-            this.profile_description = this.responses
52
-                .filter(r => r.response_key_id === config.blurbKey)
53
-                .map(r => r.val)[0]
50
+            this.profile_description = this.responses.find(
51
+                r => r.response_key_id === config.blurbKey,
52
+            ).val
54 53
             this.profile_media = this.responses
55 54
                 .filter(r => r.response_key_id === config.mediaKey)
56 55
                 .map(r => r.val)
@@ -60,43 +59,39 @@ class CompleteProfile {
60 59
         }
61 60
     }
62 61
 }
62
+const _makeCompleteProfile = (
63
+    profileEntry,
64
+    type,
65
+    tagLookup,
66
+    includeResponses,
67
+) => {
68
+    profileEntry.tags = profileEntry.tags.map(tag => tagLookup[tag.tag_id])
69
+    return new CompleteProfile(profileEntry, includeResponses, type)
70
+}
63 71
 
64
-const makeCompleteProfiles = (
65
-    profileIdArray,
72
+const makeOrderedCompleteProfiles = (
73
+    orderedProfileIds,
66 74
     profilesEntries,
67 75
     type,
68 76
     includeResponses,
69 77
     tagLookup,
70 78
 ) => {
71 79
     const completeProfiles = []
72
-    profileIdArray.forEach(pid => {
80
+    orderedProfileIds.forEach(pid => {
73 81
         profilesEntries.forEach(entry => {
74
-            if (entry.profile_id == pid) {
75
-                const complete = new CompleteProfile(
76
-                    entry,
77
-                    type,
78
-                    includeResponses,
79
-                )
80
-                tagger.setProfileTags(entry, complete, tagLookup)
81
-                completeProfiles.push(complete)
82
-            }
82
+            if (entry.profile_id != pid) return
83
+            completeProfiles.push(
84
+                _makeCompleteProfile(entry, type, tagLookup, includeResponses),
85
+            )
83 86
         })
84 87
     })
85 88
     return completeProfiles
86 89
 }
87
-const makeCompleteProfilesFromProfile = (profilesEntries, type, tagLookup) => {
88
-    profilesEntries.forEach(profile => {
89
-        tagger.setProfileTags(profile, profile, tagLookup)
90
-    })
91
-
92
-    //** Get responses asociated with each profile_id */
93
-    return profilesEntries.map(profile => {
94
-        return new CompleteProfile(profile, type)
95
-    })
96
-}
90
+const makeCompleteFromProfileEntries = (profilesEntries, type, tagLookup) =>
91
+    profilesEntries.map(entry => _makeCompleteProfile(entry, type, tagLookup))
97 92
 
98 93
 module.exports = {
99 94
     CompleteProfile,
100
-    makeCompleteProfiles,
101
-    makeCompleteProfilesFromProfile,
95
+    makeOrderedCompleteProfiles,
96
+    makeCompleteFromProfileEntries,
102 97
 }

+ 0
- 7
backend/lib/services/profile/tagger.js Wyświetl plik

@@ -1,7 +0,0 @@
1
-const setProfileTags = (inProfile, outProfile, tagLookup) => {
2
-    outProfile.tags = inProfile.tags.map(tag => tagLookup[tag.tag_id])
3
-}
4
-
5
-module.exports = {
6
-    setProfileTags,
7
-}

Ładowanie…
Anuluj
Zapisz