Kaynağa Gözat

:construction: extended the score endpoint to support filter query params- duration, presence and certifications

tags/0.0.3^2
juancarbajal98 3 yıl önce
ebeveyn
işleme
cae3863e11

+ 6
- 0
backend/lib/routes/profile/score.js Dosyayı Görüntüle

@@ -53,11 +53,17 @@ module.exports = {
53 53
             const distanceUnit = request.query.unit
54 54
                 ? request.query.unit
55 55
                 : 'mile'
56
+            const duration = request.query.duration
57
+            const presence = request.query.presence
58
+            const certifications = request.query.certifications
56 59
 
57 60
             const scoredProfiles = await profileService.scoreProfilesFor(
58 61
                 profileId,
59 62
                 maxDistanceMiles,
60 63
                 distanceUnit,
64
+                duration,
65
+                presence,
66
+                certifications,
61 67
             )
62 68
             try {
63 69
                 if (!scoredProfiles) {

+ 24
- 0
backend/lib/services/filter.js Dosyayı Görüntüle

@@ -17,8 +17,32 @@ const byMaxDistance = (profileList, max) => {
17 17
     })
18 18
 }
19 19
 
20
+const byDuration = (profileList, duration) => {
21
+    return profileList.filter(profile => {
22
+        // TODO find duration 
23
+        return profile.duration == duration
24
+    })
25
+}
26
+
27
+const byPresence = (profileList, presence) => {
28
+    return profileList.filter(profile => {
29
+        // TODO find presence 
30
+        return profile.presence == presence
31
+    })
32
+}
33
+
34
+const byCertifications = (profileList, certifications) => {
35
+    return profileList.filter(profile => {
36
+        // TODO find certifications 
37
+        return profile.certifications == certifications
38
+    })
39
+}
40
+
20 41
 module.exports = {
21 42
     byProfileType,
22 43
     byNullZip,
23 44
     byMaxDistance,
45
+    byDuration,
46
+    byPresence,
47
+    byCertifications,
24 48
 }

+ 9
- 2
backend/lib/services/profile/index.js Dosyayı Görüntüle

@@ -8,8 +8,12 @@ const zipcoder = require('./zipcoder')
8 8
 const { response } = require('@hapi/hapi/lib/validation')
9 9
 =======
10 10
 const tagger = require('./tagger')
11
+<<<<<<< HEAD
11 12
 const filter = require('./filter')
12 13
 >>>>>>> 154d171 (:construction: new filter service to preprocess a users match pool before scoring)
14
+=======
15
+const filter = require('../filter')
16
+>>>>>>> 2f11270 (:construction: extended the score endpoint to support filter query params- duration, presence and certifications)
13 17
 
14 18
 module.exports = class ProfileService extends Schmervice.Service {
15 19
     constructor(...args) {
@@ -248,7 +252,7 @@ module.exports = class ProfileService extends Schmervice.Service {
248 252
      * @param {number} profileId
249 253
      * @returns {Array} Ordered and scored Profiles
250 254
      */
251
-    async scoreProfilesFor(profileId, maxDistance, distanceUnit) {
255
+    async scoreProfilesFor(profileId, maxDistance, distanceUnit, duration, presence, certifications) {
252 256
         const { Profile } = this.server.models()
253 257
 
254 258
         await this._setScoreLookup()
@@ -270,8 +274,11 @@ module.exports = class ProfileService extends Schmervice.Service {
270 274
         matchPool = filter.byNullZip(matchPool)
271 275
         // attach distance to pool profiles for max distance filter 
272 276
         matchPool = await this.calcProfileDistances(matchPool, distanceUnit, userZip)
273
-        // filter with matchPool profiles that have distance
274 277
         matchPool = filter.byMaxDistance(matchPool, maxDistance)
278
+        matchPool = filter.byDuration(matchPool, duration)
279
+        matchPool = filter.byPresence(matchPool, presence)
280
+        matchPool = filter.byCertifications(matchPool, certifications)
281
+
275 282
 
276 283
         const scoredProfilesWithDistance = scoring.scoreAll(
277 284
             matchPool,

+ 2
- 2
frontend/src/services/survey.service.js Dosyayı Görüntüle

@@ -49,9 +49,9 @@ const updateSurveyByProfileId = async (surveyResponses, profileId) => {
49 49
     })
50 50
 }
51 51
 
52
-const scoreSurveyByProfileId = async (profileId, maxDistance = 99) => {
52
+const scoreSurveyByProfileId = async (profileId, maxDistance = 99, duration, presence, certifications) => {
53 53
     const scoreSurvey = await db.get(
54
-        `/profile/${profileId}/score?max_distance=${maxDistance}`,
54
+        `/profile/${profileId}/score?max_distance=${maxDistance}&duration=${duration}&presence=${presence}&certifications=${certifications}`,
55 55
     )
56 56
     return scoreSurvey
57 57
 }

+ 24
- 1
frontend/src/views/SurveyView.vue Dosyayı Görüntüle

@@ -207,7 +207,13 @@ export default {
207 207
 
208 208
             return userProfileRel
209 209
         },
210
-        async _getProfileWithScore(createdProfileId, maxDistance) {
210
+        async _getProfileWithScore(
211
+            createdProfileId,
212
+            maxDistance,
213
+            duration,
214
+            presence,
215
+            certifications,
216
+        ) {
211 217
             /** A Profile is associated with n:1 user and referenced by profile id */
212 218
             const fetchedProfile = await fetchProfileByProfileId(
213 219
                 createdProfileId,
@@ -223,6 +229,9 @@ export default {
223 229
             const scored = await scoreSurveyByProfileId(
224 230
                 createdProfileId,
225 231
                 maxDistance,
232
+                duration,
233
+                presence,
234
+                certifications,
226 235
             )
227 236
             if (!scored) {
228 237
                 console.error(`Could not score Profile ${createdProfileId}.`)
@@ -250,6 +259,17 @@ export default {
250 259
             const maxDistanceRes = survey.find(
251 260
                 res => res.response_key_id == distanceKey,
252 261
             )
262
+            const duration = survey.find(
263
+                res => res.response_key_id == prefKeys[1], // == 10
264
+            )
265
+            const presence = survey.find(
266
+                res => (res.response_key_id = prefKeys[2]), // == 11
267
+            )
268
+            // TODO find certifications in responses
269
+            const certifications = survey.find(
270
+                res => (res.response_key_id = certifications),
271
+            )
272
+
253 273
             /**
254 274
              * Creating a profile only returns the created
255 275
              * user id and profile id
@@ -264,6 +284,9 @@ export default {
264 284
             const fetchedProfile = await this._getProfileWithScore(
265 285
                 createdProfileId,
266 286
                 maxDistanceRes.val,
287
+                duration.val,
288
+                presence.val,
289
+                certifications.val,
267 290
             )
268 291
 
269 292
             /**

Loading…
İptal
Kaydet