|
|
@@ -4,16 +4,7 @@ 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
|
|
-<<<<<<< HEAD
|
|
8
|
|
-const { response } = require('@hapi/hapi/lib/validation')
|
|
9
|
|
-=======
|
|
10
|
|
-const tagger = require('./tagger')
|
|
11
|
|
-<<<<<<< HEAD
|
|
12
|
|
-const filter = require('./filter')
|
|
13
|
|
->>>>>>> 154d171 (:construction: new filter service to preprocess a users match pool before scoring)
|
|
14
|
|
-=======
|
|
15
|
7
|
const filter = require('../filter')
|
|
16
|
|
->>>>>>> 2f11270 (:construction: extended the score endpoint to support filter query params- duration, presence and certifications)
|
|
17
|
8
|
|
|
18
|
9
|
module.exports = class ProfileService extends Schmervice.Service {
|
|
19
|
10
|
constructor(...args) {
|
|
|
@@ -252,7 +243,14 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
252
|
243
|
* @param {number} profileId
|
|
253
|
244
|
* @returns {Array} Ordered and scored Profiles
|
|
254
|
245
|
*/
|
|
255
|
|
- async scoreProfilesFor(profileId, maxDistance, distanceUnit, duration, presence, certifications) {
|
|
|
246
|
+ async scoreProfilesFor(
|
|
|
247
|
+ profileId,
|
|
|
248
|
+ maxDistance,
|
|
|
249
|
+ distanceUnit,
|
|
|
250
|
+ duration,
|
|
|
251
|
+ presence,
|
|
|
252
|
+ certifications,
|
|
|
253
|
+ ) {
|
|
256
|
254
|
const { Profile } = this.server.models()
|
|
257
|
255
|
|
|
258
|
256
|
await this._setScoreLookup()
|
|
|
@@ -262,7 +260,7 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
262
|
260
|
.findOne('profile_id', profileId)
|
|
263
|
261
|
.withGraphFetched('responses')
|
|
264
|
262
|
.withGraphFetched('user')
|
|
265
|
|
-
|
|
|
263
|
+
|
|
266
|
264
|
const userZip = zipcoder.getZipCodeFromProfile(userProfile)
|
|
267
|
265
|
|
|
268
|
266
|
// preprocess potential match pool with filter service methods
|
|
|
@@ -272,14 +270,17 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
272
|
270
|
|
|
273
|
271
|
matchPool = filter.byProfileType(matchPool, userProfile.user)
|
|
274
|
272
|
matchPool = filter.byNullZip(matchPool)
|
|
275
|
|
- // attach distance to pool profiles for max distance filter
|
|
276
|
|
- matchPool = await this.calcProfileDistances(matchPool, distanceUnit, userZip)
|
|
|
273
|
+ // attach distance to pool profiles for max distance filter
|
|
|
274
|
+ matchPool = await this.calcProfileDistances(
|
|
|
275
|
+ matchPool,
|
|
|
276
|
+ distanceUnit,
|
|
|
277
|
+ userZip,
|
|
|
278
|
+ )
|
|
277
|
279
|
matchPool = filter.byMaxDistance(matchPool, maxDistance)
|
|
278
|
280
|
matchPool = filter.byDuration(matchPool, duration)
|
|
279
|
281
|
matchPool = filter.byPresence(matchPool, presence)
|
|
280
|
282
|
matchPool = filter.byCertifications(matchPool, certifications)
|
|
281
|
283
|
|
|
282
|
|
-
|
|
283
|
284
|
const scoredProfilesWithDistance = scoring.scoreAll(
|
|
284
|
285
|
matchPool,
|
|
285
|
286
|
userProfile,
|
|
|
@@ -291,7 +292,7 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
291
|
292
|
)
|
|
292
|
293
|
}
|
|
293
|
294
|
|
|
294
|
|
- async calcProfileDistances(matchPool, distanceUnit, userZip){
|
|
|
295
|
+ async calcProfileDistances(matchPool, distanceUnit, userZip) {
|
|
295
|
296
|
await Promise.all(
|
|
296
|
297
|
matchPool.map(async profile => {
|
|
297
|
298
|
const targetZip = zipcoder.getZipCodeFromProfile(profile)
|
|
|
@@ -307,7 +308,7 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
307
|
308
|
...profile,
|
|
308
|
309
|
distance: [distance.toFixed(2), distanceUnit],
|
|
309
|
310
|
}
|
|
310
|
|
- })
|
|
|
311
|
+ }),
|
|
311
|
312
|
)
|
|
312
|
313
|
}
|
|
313
|
314
|
|
|
|
@@ -355,8 +356,8 @@ module.exports = class ProfileService extends Schmervice.Service {
|
|
355
|
356
|
await this._setTagLookup()
|
|
356
|
357
|
let associations = groupingId
|
|
357
|
358
|
? await TagAssociation.query()
|
|
358
|
|
- .where('grouping_id', groupingId)
|
|
359
|
|
- .andWhere('profile_id', profileId)
|
|
|
359
|
+ .where('grouping_id', groupingId)
|
|
|
360
|
+ .andWhere('profile_id', profileId)
|
|
360
|
361
|
: await TagAssociation.query().andWhere('profile_id', profileId)
|
|
361
|
362
|
return associations
|
|
362
|
363
|
.map(assoc => ({
|