|
|
@@ -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,14 +53,15 @@ 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
|
66
|
return this.setDefaults(complete)
|
|
68
|
67
|
}
|
|
|
@@ -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,
|
|
|
@@ -231,10 +230,10 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
231
|
230
|
* @param {object} complete
|
|
232
|
231
|
* @returns {object} updated profile
|
|
233
|
232
|
*/
|
|
234
|
|
- setDefaults(complete){
|
|
|
233
|
+ setDefaults(complete) {
|
|
235
|
234
|
let defaultValues = {
|
|
236
|
235
|
user_email: 'hidden@email.com',
|
|
237
|
|
- user_name: 'Hidden Name'
|
|
|
236
|
+ user_name: 'Hidden Name',
|
|
238
|
237
|
}
|
|
239
|
238
|
|
|
240
|
239
|
let defaultProfile = {
|
|
|
@@ -242,14 +241,20 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
242
|
241
|
user_email: defaultValues.user_email,
|
|
243
|
242
|
user_name: defaultValues.user_name,
|
|
244
|
243
|
}
|
|
245
|
|
- console.log('defaultProfile: ', defaultProfile)
|
|
246
|
|
- if(!complete.reveal.length) return defaultProfile // nothing to reveal
|
|
|
244
|
+ console.log('---')
|
|
|
245
|
+ console.log('defaultProfile: ', defaultProfile.user_email)
|
|
|
246
|
+ if (!complete.reveal.length) return defaultProfile // nothing to reveal
|
|
247
|
247
|
|
|
248
|
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
|
|
|
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
|
|
251
|
256
|
}
|
|
252
|
|
- console.log('complete: ', complete)
|
|
|
257
|
+ console.log('complete: ', complete.user_email)
|
|
253
|
258
|
|
|
254
|
259
|
return complete
|
|
255
|
260
|
}
|
|
|
@@ -384,8 +389,8 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
384
|
389
|
await this._setTagLookup()
|
|
385
|
390
|
let associations = groupingId
|
|
386
|
391
|
? await TagAssociation.query()
|
|
387
|
|
- .where('grouping_id', groupingId)
|
|
388
|
|
- .andWhere('profile_id', profileId)
|
|
|
392
|
+ .where('grouping_id', groupingId)
|
|
|
393
|
+ .andWhere('profile_id', profileId)
|
|
389
|
394
|
: await TagAssociation.query().andWhere('profile_id', profileId)
|
|
390
|
395
|
return associations
|
|
391
|
396
|
.map(assoc => ({
|