Procházet zdrojové kódy

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

tags/0.0.3^2
juancarbajal98 před 3 roky
rodič
revize
cae3863e11

+ 6
- 0
backend/lib/routes/profile/score.js Zobrazit soubor

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

+ 24
- 0
backend/lib/services/filter.js Zobrazit soubor

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
 module.exports = {
41
 module.exports = {
21
     byProfileType,
42
     byProfileType,
22
     byNullZip,
43
     byNullZip,
23
     byMaxDistance,
44
     byMaxDistance,
45
+    byDuration,
46
+    byPresence,
47
+    byCertifications,
24
 }
48
 }

+ 9
- 2
backend/lib/services/profile/index.js Zobrazit soubor

8
 const { response } = require('@hapi/hapi/lib/validation')
8
 const { response } = require('@hapi/hapi/lib/validation')
9
 =======
9
 =======
10
 const tagger = require('./tagger')
10
 const tagger = require('./tagger')
11
+<<<<<<< HEAD
11
 const filter = require('./filter')
12
 const filter = require('./filter')
12
 >>>>>>> 154d171 (:construction: new filter service to preprocess a users match pool before scoring)
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
 module.exports = class ProfileService extends Schmervice.Service {
18
 module.exports = class ProfileService extends Schmervice.Service {
15
     constructor(...args) {
19
     constructor(...args) {
248
      * @param {number} profileId
252
      * @param {number} profileId
249
      * @returns {Array} Ordered and scored Profiles
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
         const { Profile } = this.server.models()
256
         const { Profile } = this.server.models()
253
 
257
 
254
         await this._setScoreLookup()
258
         await this._setScoreLookup()
270
         matchPool = filter.byNullZip(matchPool)
274
         matchPool = filter.byNullZip(matchPool)
271
         // attach distance to pool profiles for max distance filter 
275
         // attach distance to pool profiles for max distance filter 
272
         matchPool = await this.calcProfileDistances(matchPool, distanceUnit, userZip)
276
         matchPool = await this.calcProfileDistances(matchPool, distanceUnit, userZip)
273
-        // filter with matchPool profiles that have distance
274
         matchPool = filter.byMaxDistance(matchPool, maxDistance)
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
         const scoredProfilesWithDistance = scoring.scoreAll(
283
         const scoredProfilesWithDistance = scoring.scoreAll(
277
             matchPool,
284
             matchPool,

+ 2
- 2
frontend/src/services/survey.service.js Zobrazit soubor

49
     })
49
     })
50
 }
50
 }
51
 
51
 
52
-const scoreSurveyByProfileId = async (profileId, maxDistance = 99) => {
52
+const scoreSurveyByProfileId = async (profileId, maxDistance = 99, duration, presence, certifications) => {
53
     const scoreSurvey = await db.get(
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
     return scoreSurvey
56
     return scoreSurvey
57
 }
57
 }

+ 24
- 1
frontend/src/views/SurveyView.vue Zobrazit soubor

207
 
207
 
208
             return userProfileRel
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
             /** A Profile is associated with n:1 user and referenced by profile id */
217
             /** A Profile is associated with n:1 user and referenced by profile id */
212
             const fetchedProfile = await fetchProfileByProfileId(
218
             const fetchedProfile = await fetchProfileByProfileId(
213
                 createdProfileId,
219
                 createdProfileId,
223
             const scored = await scoreSurveyByProfileId(
229
             const scored = await scoreSurveyByProfileId(
224
                 createdProfileId,
230
                 createdProfileId,
225
                 maxDistance,
231
                 maxDistance,
232
+                duration,
233
+                presence,
234
+                certifications,
226
             )
235
             )
227
             if (!scored) {
236
             if (!scored) {
228
                 console.error(`Could not score Profile ${createdProfileId}.`)
237
                 console.error(`Could not score Profile ${createdProfileId}.`)
250
             const maxDistanceRes = survey.find(
259
             const maxDistanceRes = survey.find(
251
                 res => res.response_key_id == distanceKey,
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
              * Creating a profile only returns the created
274
              * Creating a profile only returns the created
255
              * user id and profile id
275
              * user id and profile id
264
             const fetchedProfile = await this._getProfileWithScore(
284
             const fetchedProfile = await this._getProfileWithScore(
265
                 createdProfileId,
285
                 createdProfileId,
266
                 maxDistanceRes.val,
286
                 maxDistanceRes.val,
287
+                duration.val,
288
+                presence.val,
289
+                certifications.val,
267
             )
290
             )
268
 
291
 
269
             /**
292
             /**

Načítá se…
Zrušit
Uložit