Просмотр исходного кода

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

tags/0.0.3^2
maeda 3 лет назад
Родитель
Сommit
646c223461

+ 1
- 1
backend/db/data-generator/config.json Просмотреть файл

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

+ 1
- 1
backend/db/data-generator/mock.js Просмотреть файл

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

+ 50
- 17
backend/lib/services/profile/index.js Просмотреть файл

4
 const profiler = require('./profiler')
4
 const profiler = require('./profiler')
5
 const scoring = require('./scorer')
5
 const scoring = require('./scorer')
6
 const zipcoder = require('./zipcoder')
6
 const zipcoder = require('./zipcoder')
7
-const tagger = require('./tagger')
8
 
7
 
9
 module.exports = class ProfileService extends Schmervice.Service {
8
 module.exports = class ProfileService extends Schmervice.Service {
10
     constructor(...args) {
9
     constructor(...args) {
24
         }
23
         }
25
     }
24
     }
26
     async _setTagLookup() {
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
      * Internal method to get list of profile_ids for this user
36
      * Internal method to get list of profile_ids for this user
55
     async getProfile(profileId) {
53
     async getProfile(profileId) {
56
         const { Profile } = this.server.models()
54
         const { Profile } = this.server.models()
57
         await this._setTagLookup()
55
         await this._setTagLookup()
58
-
59
         const matchingProfile = await Profile.query()
56
         const matchingProfile = await Profile.query()
60
             .where('profile_id', profileId)
57
             .where('profile_id', profileId)
61
             .first()
58
             .first()
62
             .withGraphFetched('tags')
59
             .withGraphFetched('tags')
63
             .withGraphFetched('responses')
60
             .withGraphFetched('responses')
64
             .withGraphFetched('user')
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
         const complete = new profiler.CompleteProfile(matchingProfile, true)
65
         const complete = new profiler.CompleteProfile(matchingProfile, true)
67
-        return complete
66
+        return this.setDefaults(complete)
68
     }
67
     }
69
 
68
 
70
     async getCompleteProfilesFor(userId, type) {
69
     async getCompleteProfilesFor(userId, type) {
81
             // so without this, we get undefined user_name
80
             // so without this, we get undefined user_name
82
             .withGraphFetched('user')
81
             .withGraphFetched('user')
83
 
82
 
84
-        return profiler.makeCompleteProfilesFromProfile(
83
+        return profiler.makeCompleteFromProfileEntries(
85
             profilesEntries,
84
             profilesEntries,
86
             type,
85
             type,
87
             this.tagLookup,
86
             this.tagLookup,
103
         // taking the info from profilesEntries
102
         // taking the info from profilesEntries
104
         // to repack into completeProfiles
103
         // to repack into completeProfiles
105
         // in same order as profileIdArray
104
         // in same order as profileIdArray
106
-        return profiler.makeCompleteProfiles(
105
+        return profiler.makeOrderedCompleteProfiles(
107
             profileIdArray,
106
             profileIdArray,
108
             profilesEntries,
107
             profilesEntries,
109
             type,
108
             type,
226
         return allResponses
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
      * Delete a profile
263
      * Delete a profile
231
      * @param {number} userId
264
      * @param {number} userId
356
         await this._setTagLookup()
389
         await this._setTagLookup()
357
         let associations = groupingId
390
         let associations = groupingId
358
             ? await TagAssociation.query()
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
             : await TagAssociation.query().andWhere('profile_id', profileId)
394
             : await TagAssociation.query().andWhere('profile_id', profileId)
362
         return associations
395
         return associations
363
             .map(assoc => ({
396
             .map(assoc => ({

+ 26
- 31
backend/lib/services/profile/profiler.js Просмотреть файл

1
 const config = require('../../../db/data-generator/config.json')
1
 const config = require('../../../db/data-generator/config.json')
2
-const tagger = require('./tagger')
3
 
2
 
4
 /**
3
 /**
5
  * Class to hold our retrieved profile information
4
  * Class to hold our retrieved profile information
27
         // TODO: Use reveal tags to rebuild profile based on group/membership
26
         // TODO: Use reveal tags to rebuild profile based on group/membership
28
         // TODO: and include for certain profiles
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
         // TODO: filter these correctly
30
         // TODO: filter these correctly
32
         if (profile?.responses?.length && includeResponses) {
31
         if (profile?.responses?.length && includeResponses) {
33
             // [] of all "profile" responses
32
             // [] of all "profile" responses
44
             ]
43
             ]
45
             const prefsKeys = config.prefKeys
44
             const prefsKeys = config.prefKeys
46
             prefs.forEach((pref, i) => {
45
             prefs.forEach((pref, i) => {
47
-                this.profile_prefs[pref] = this.responses.filter(
46
+                this.profile_prefs[pref] = this.responses.find(
48
                     r => r.response_key_id === prefsKeys[i],
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
             this.profile_media = this.responses
53
             this.profile_media = this.responses
55
                 .filter(r => r.response_key_id === config.mediaKey)
54
                 .filter(r => r.response_key_id === config.mediaKey)
56
                 .map(r => r.val)
55
                 .map(r => r.val)
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
     profilesEntries,
74
     profilesEntries,
67
     type,
75
     type,
68
     includeResponses,
76
     includeResponses,
69
     tagLookup,
77
     tagLookup,
70
 ) => {
78
 ) => {
71
     const completeProfiles = []
79
     const completeProfiles = []
72
-    profileIdArray.forEach(pid => {
80
+    orderedProfileIds.forEach(pid => {
73
         profilesEntries.forEach(entry => {
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
     return completeProfiles
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
 module.exports = {
93
 module.exports = {
99
     CompleteProfile,
94
     CompleteProfile,
100
-    makeCompleteProfiles,
101
-    makeCompleteProfilesFromProfile,
95
+    makeOrderedCompleteProfiles,
96
+    makeCompleteFromProfileEntries,
102
 }
97
 }

+ 0
- 7
backend/lib/services/profile/tagger.js Просмотреть файл

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
-}

Загрузка…
Отмена
Сохранить