9 Incheckningar

Upphovsman SHA1 Meddelande Datum
  tomit4 1306c20fe5 :construction: Started to finalize Survey Complete Page 2 år sedan
  tomit4 3bb6ea1c6d :bug: Addressed bugs involving validation and groupings 2 år sedan
  tomit4 1ff7fe78d2 :construction: Continued filtering logic for initial survey answers 2 år sedan
  tomit4 e60c0555cd :pencil2: Fixed merge issues 2 år sedan
  tomit4 92a16c0eea :pencil2: Fixed merge conflicts 2 år sedan
  tomit4 01fe3ccba4 :pencil2: Fixed merge conflicts 2 år sedan
  tomit4 8fe99958e3 :pencil2: Edited filter service to reflect code style of other plugins 2 år sedan
  juancarbajal98 f4af0e4376 :gears: migrating filtering logic to backend in new filter plugin 2 år sedan
  juancarbajal98 93e263b1ec :gears: WIP finalSubmit function at end of onboarding 2 år sedan

+ 1
- 53
backend/db/data-generator/mock.js Visa fil

@@ -431,7 +431,7 @@ module.exports = {
431 431
         // TODO: remove from mock data once bare bones matching logic can show poorly matched matches...
432 432
         {
433 433
             tag_association_id: 50,
434
-            profile_id: 136,
434
+            profile_id: 139,
435 435
             grouping_id: 2,
436 436
             tag_id: 7,
437 437
             is_deleted: false,
@@ -682,18 +682,6 @@ module.exports = {
682 682
             can_edit: false,
683 683
             is_active: true,
684 684
         },
685
-        // NOTE: profile_id 147 is chosen based off of GENERATED data,
686
-        // after running 'npm run generate', replace 147 in mock to next profile_id to be genearted
687
-        // i.e. last profile_id number + 1
688
-        // TODO: remove from mock data once bare bones matching logic can show poorly matched matches...
689
-        {
690
-            membership_id: 3,
691
-            profile_id: 147,
692
-            grouping_id: 2,
693
-            membership_type: 'participant',
694
-            can_edit: false,
695
-            is_active: true,
696
-        },
697 685
         {
698 686
             membership_id: 4,
699 687
             profile_id: 46,
@@ -768,45 +756,5 @@ module.exports = {
768 756
             target_id: 46,
769 757
             is_deleted: false,
770 758
         },
771
-        // NOTE: profile_id 147 is chosen based off of GENERATED data,
772
-        // after running 'npm run generate', replace 147 in mock to next profile_id to be generated
773
-        // i.e. last profile_id number + 1
774
-        // TODO: remove from mock data once bare bones matching logic can show poorly matched matches...
775
-        {
776
-            match_queue_id: 17,
777
-            profile_id: 147,
778
-            target_id: 46,
779
-            is_deleted: false,
780
-        },
781
-        {
782
-            match_queue_id: 18,
783
-            profile_id: 147,
784
-            target_id: 46,
785
-            is_deleted: false,
786
-        },
787
-        {
788
-            match_queue_id: 19,
789
-            profile_id: 147,
790
-            target_id: 44,
791
-            is_deleted: false,
792
-        },
793
-        {
794
-            match_queue_id: 20,
795
-            profile_id: 147,
796
-            target_id: 43,
797
-            is_deleted: false,
798
-        },
799
-        {
800
-            match_queue_id: 21,
801
-            profile_id: 147,
802
-            target_id: 42,
803
-            is_deleted: false,
804
-        },
805
-        {
806
-            match_queue_id: 22,
807
-            profile_id: 147,
808
-            target_id: 41,
809
-            is_deleted: false,
810
-        },
811 759
     ],
812 760
 }

+ 9
- 9
backend/db/seeds/04-responses.js Visa fil

@@ -12,24 +12,24 @@ for (let name of fileNames) {
12 12
         responses = [...responses, ...data.responses]
13 13
     }
14 14
 }
15
-
16 15
 /**
17 16
  * Prevent seeding responses for
18 17
  * profile ids so we can test oboarding
19 18
  */
20
-responses = dataSort(responses, 'response_id').filter(
21
-    response => !ignore.includes(response.profile_id),
22
-)
19
+// responses = dataSort(responses, 'response_id').filter(
20
+// response => !ignore.includes(response.profile_id),
21
+// )
23 22
 
24 23
 exports.seed = async knex => {
25 24
     await knex('responses').del()
26 25
     let responsesToPush = []
27
-    let len = responses.length
26
+    const len = responses.length
28 27
     for (let i = 1; i <= len; i += 1) {
29 28
         responsesToPush.push(responses.shift())
30
-        if (i % batchSize === 0 || i > responses.length) {
31
-            // await knex('responses').insert(responsesToPush)
32
-            responsesToPush = []
33
-        }
29
+        // if (i % batchSize === 0 || i > responses.length) {
30
+        // await knex('responses').insert(responsesToPush)
31
+        // responsesToPush = []
32
+        // }
34 33
     }
34
+    await knex('responses').insert(responsesToPush)
35 35
 }

+ 5
- 0
backend/lib/index.js Visa fil

@@ -4,6 +4,7 @@ const SurveyPlugin = require('./plugins/survey')
4 4
 const ProfilePlugin = require('./plugins/profile')
5 5
 const NotificationPlugin = require('./plugins/notification')
6 6
 const HealthPlugin = require('./plugins/health')
7
+const FilterPlugin = require('./plugins/filter')
7 8
 
8 9
 /**
9 10
  * A Hapi server instance
@@ -50,5 +51,9 @@ exports.plugin = {
50 51
         await server.register(HealthPlugin, {
51 52
             routes: { prefix: '/health' },
52 53
         })
54
+
55
+        await server.register(FilterPlugin, {
56
+            routes: { prefix: '/filter' },
57
+        })
53 58
     },
54 59
 }

+ 13
- 0
backend/lib/plugins/filter.js Visa fil

@@ -0,0 +1,13 @@
1
+const Schmervice = require('@hapipal/schmervice')
2
+const FilterRoute = require('../routes/filter/get')
3
+const FilterService = require('../services/filter')
4
+
5
+module.exports = {
6
+    name: 'filter-plugin',
7
+    version: '1.0.0',
8
+    register: async (server, options) => {
9
+        await server.register(Schmervice)
10
+        await server.registerService(FilterService)
11
+        await server.route(FilterRoute)
12
+    },
13
+}

+ 89
- 0
backend/lib/routes/filter/get.js Visa fil

@@ -0,0 +1,89 @@
1
+'use strict'
2
+
3
+// NOTE: Current Implementation does not require this route
4
+// (see Auth.vue in components/onboarding and queue route with filter.js)
5
+const Joi = require('joi')
6
+const apiSchema = require('../../schemas/api')
7
+const errorSchema = require('../../schemas/errors')
8
+const filterSchema = require('../../schemas/filter')
9
+const profileSchema = require('../../schemas/profiles')
10
+
11
+const pluginConfig = {
12
+    handlerType: 'filter',
13
+    docs: {
14
+        description: 'Filter match pool',
15
+        notes: 'Returns filtered subset of match pool',
16
+    },
17
+}
18
+
19
+const validators = {
20
+    query: Joi.object({
21
+        match_pool: Joi.array().items(profileSchema.single),
22
+        distance: Joi.string(),
23
+        presence: Joi.string(),
24
+    }),
25
+}
26
+
27
+const responseSchemas = {
28
+    filteredMatchPool: filterSchema.matchPool, // array of profiles
29
+    error: errorSchema.single,
30
+}
31
+
32
+module.exports = {
33
+    method: 'GET',
34
+    path: '/',
35
+    options: {
36
+        ...pluginConfig.docs,
37
+        tags: ['api'],
38
+        auth: false,
39
+        cors: true,
40
+        handler: async function (request, h) {
41
+            const { filterService } = request.server.services()
42
+            let matchPool = request.query.match_pool
43
+            matchPool = filterService.byDistance(
44
+                matchPool,
45
+                request.query.distance,
46
+            )
47
+            matchPool = filterService.byPresence(
48
+                matchPool,
49
+                request.query.presence,
50
+            )
51
+            try {
52
+                return h
53
+                    .response({
54
+                        ok: true,
55
+                        handler: pluginConfig.handlerType,
56
+                        data: matchPool,
57
+                    })
58
+                    .code(200)
59
+            } catch (err) {
60
+                return h
61
+                    .response({
62
+                        ok: false,
63
+                        handler: pluginConfig.handlerType,
64
+                        data: { error: `${err}` },
65
+                    })
66
+                    .code(409)
67
+            }
68
+        },
69
+        validate: {
70
+            ...validators,
71
+            failAction: 'log',
72
+        },
73
+
74
+        response: {
75
+            status: {
76
+                200: apiSchema.single
77
+                    .append({
78
+                        data: responseSchemas.filteredMatchPool,
79
+                    })
80
+                    .label('api_single_res'),
81
+                409: apiSchema.single
82
+                    .append({
83
+                        data: responseSchemas.error,
84
+                    })
85
+                    .label('error_single_res'),
86
+            },
87
+        },
88
+    },
89
+}

+ 27
- 20
backend/lib/routes/membership/active.js Visa fil

@@ -71,19 +71,24 @@ module.exports = {
71 71
                 profileId,
72 72
                 membershipType,
73 73
             )
74
+            if (!groupings.length) {
75
+                return {
76
+                    ok: true,
77
+                    handler: pluginConfig.handlerType,
78
+                    data: [],
79
+                }
80
+            }
74 81
             const groupingIds = groupings.map(grouping => grouping.grouping_id)
75
-            const memberships = await membershipService.findMemberships(
76
-                groupingIds,
77
-            )
82
+            const memberships =
83
+                await membershipService.findMemberships(groupingIds)
78 84
             const profileIds = memberships
79 85
                 .filter(membership => membership.profile_id != profileId)
80 86
                 .map(membership => membership.profile_id)
81 87
 
82 88
             /** Assemble complete profiles to reference and pass */
83
-            const completedProfiles = await profileService.getProfilesFor(
84
-                profileIds,
85
-                'participant',
86
-            )
89
+            const completedProfiles = !profileIds.length
90
+                ? []
91
+                : await profileService.getProfilesFor(profileIds, 'participant')
87 92
 
88 93
             /**
89 94
              * Heavily process the result by storing just a profile_id
@@ -91,19 +96,21 @@ module.exports = {
91 96
              * !: This still assumes only ONE other profile
92 97
              * TODO: should be refactored to many other profiles
93 98
              */
94
-            const reformattedGroupings = groupings.map(grouping => {
95
-                const otherPid = grouping.profiles.find(
96
-                    p => p.profile_id != profileId,
97
-                ).profile_id
98
-                grouping.profile = completedProfiles.find(
99
-                    p => otherPid == p.profile_id,
100
-                )
101
-                grouping.is_paired = _activeGroupingIds(memberships).includes(
102
-                    grouping.grouping_id,
103
-                )
104
-                delete grouping.profiles
105
-                return grouping
106
-            })
99
+            const reformattedGroupings = groupings.length
100
+                ? groupings.map(grouping => {
101
+                      const otherPid = grouping.profiles.find(
102
+                          p => p.profile_id != profileId,
103
+                      ).profile_id
104
+                      grouping.profile = completedProfiles.find(
105
+                          p => otherPid == p.profile_id,
106
+                      )
107
+                      grouping.is_paired = _activeGroupingIds(
108
+                          memberships,
109
+                      ).includes(grouping.grouping_id)
110
+                      delete grouping.profiles
111
+                      return grouping
112
+                  })
113
+                : []
107 114
 
108 115
             /** Grabs revealTags */
109 116
             const revealTags = await profileService.getTagsFor(

+ 7
- 3
backend/lib/routes/profile/score.js Visa fil

@@ -53,10 +53,14 @@ 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
56
+            const duration = request.query.duration.includes('-')
57
+                ? request.query.duration.split('-')[0]
58
+                : request.query.duration
59
+            const presence =
60
+                request.query.presence === 'in_person'
61
+                    ? 'onsite'
62
+                    : request.query.presence
58 63
             const certifications = request.query.certifications
59
-
60 64
             const scoredProfiles = await profileService.scoreProfilesFor(
61 65
                 profileId,
62 66
                 maxDistanceMiles,

+ 69
- 0
backend/lib/routes/user/get-session.js Visa fil

@@ -0,0 +1,69 @@
1
+'use strict'
2
+
3
+const Joi = require('joi')
4
+
5
+const pluginConfig = {
6
+    handlerType: 'authentication',
7
+    docs: {
8
+        get: {
9
+            description: 'creates session token for authentication',
10
+            notes: 'Creates session token for authentication',
11
+        },
12
+    },
13
+}
14
+
15
+const validators = {
16
+    payload: Joi.object({
17
+        payload: Joi.object({
18
+            email: Joi.string(),
19
+            name: Joi.string(),
20
+            seeking: Joi.string(),
21
+        }),
22
+    }),
23
+}
24
+
25
+module.exports = {
26
+    method: 'POST',
27
+    path: '/token',
28
+    options: {
29
+        ...pluginConfig.docs.get,
30
+        tags: ['api'],
31
+        auth: false,
32
+        cors: {
33
+            headers: ['Authorization', 'Content-Type'],
34
+            exposedHeaders: ['Authorization', 'Access-Control-Expose-Headers'],
35
+        },
36
+        handler: async function (request, h) {
37
+            const { userService } = request.server.services()
38
+            const res = request.payload
39
+            // NOTE: Session Token set for 5 minutes expiration (default)
40
+            const sessionToken = await userService.createToken(res, 600)
41
+            try {
42
+                const response = h.response({
43
+                    ok: true,
44
+                    handler: pluginConfig.handlerType,
45
+                    data: sessionToken,
46
+                })
47
+                response.header('Authorization', sessionToken)
48
+                return response
49
+            } catch (err) {
50
+                return {
51
+                    ok: false,
52
+                    handler: pluginConfig.handlerType,
53
+                    data: {
54
+                        error: err,
55
+                    },
56
+                }
57
+            }
58
+        },
59
+        validate: {
60
+            ...validators,
61
+            failAction: 'log',
62
+        },
63
+        response: {
64
+            // TODO: change back to accommodate new h.response return values
65
+            schema: Joi.any().label('get_session_res'),
66
+            failAction: 'log',
67
+        },
68
+    },
69
+}

+ 8
- 0
backend/lib/schemas/filter.js Visa fil

@@ -0,0 +1,8 @@
1
+'use strict'
2
+
3
+const Joi = require('joi')
4
+const profileSchema = require('./profiles')
5
+
6
+module.exports = { 
7
+    matchPool: Joi.array().items(profileSchema.single).label('matchPool')
8
+}

+ 1
- 0
backend/lib/schemas/profiles.js Visa fil

@@ -15,6 +15,7 @@ const singleProfile = Joi.object({
15 15
     tags: tagSchema.list,
16 16
     media: Joi.any(),
17 17
     blurb: Joi.any(),
18
+    image: Joi.any(),
18 19
     user_type: Joi.any(),
19 20
     user: userSchema.single,
20 21
     profile_description: Joi.string().allow(null, ''),

+ 63
- 43
backend/lib/services/filter.js Visa fil

@@ -1,48 +1,68 @@
1
-const zipcoder = require ('./profile/zipcoder')
1
+const zipcoder = require('./profile/zipcoder')
2
+const Schmervice = require('@hapipal/schmervice')
2 3
 
3
-const byProfileType = (profileList, userProfile) => {
4
-    const isUserOpposite = userProfile.is_poster == 1 ? 0 : 1
5
-    return profileList.filter(profile => (profile.user.is_poster == isUserOpposite))
6
-}
7
-const byNullZip = (profileList) => {
8
-    return profileList.filter(profile => {
9
-        return zipcoder.getZipCodeFromProfile(profile) ? true : false
10
-    })
11
-}
12
-const byMaxDistance = (profileList, max) => {
13
-    return profileList.filter(profile => {
14
-        const profileDistance = Math.floor(parseFloat(profile.distance) * 100)
15
-        const adjustedMaxDistance = Math.floor(parseFloat(max) * 100)
16
-        return profileDistance <= adjustedMaxDistance
17
-    })
18
-}
4
+module.exports = class FilterService extends Schmervice.Service {
5
+    constructor(...args) {
6
+        super(...args)
7
+    }
19 8
 
20
-const byDuration = (profileList, duration) => {
21
-    return profileList.filter(profile => {
22
-        // TODO find duration 
23
-        return profile.duration == duration
24
-    })
25
-}
9
+    byProfileType(profileList, userProfile) {
10
+        const isUserOpposite = userProfile.is_poster === 1 ? 0 : 1
11
+        return profileList.filter(
12
+            profile => profile.user.is_poster === isUserOpposite,
13
+        )
14
+    }
26 15
 
27
-const byPresence = (profileList, presence) => {
28
-    return profileList.filter(profile => {
29
-        // TODO find presence 
30
-        return profile.presence == presence
31
-    })
32
-}
16
+    byNullZip(profileList) {
17
+        return profileList.filter(profile => {
18
+            return zipcoder.getZipCodeFromProfile(profile) ? true : false
19
+        })
20
+    }
33 21
 
34
-const byCertifications = (profileList, certifications) => {
35
-    return profileList.filter(profile => {
36
-        // TODO find certifications 
37
-        return profile.certifications == certifications
38
-    })
39
-}
22
+    byDistance(profileList, max) {
23
+        return profileList.filter(profile => {
24
+            const profileDistance = Math.floor(
25
+                parseFloat(profile.distance) * 100,
26
+            )
27
+            const adjustedMaxDistance = Math.floor(parseFloat(max) * 100)
28
+            return profileDistance <= adjustedMaxDistance
29
+        })
30
+    }
31
+
32
+    byPresence(profileList, presence) {
33
+        const matchingProfiles = []
34
+        for (const profile of profileList) {
35
+            for (const response of profile.responses) {
36
+                if (
37
+                    response.response_key_id === 15 &&
38
+                    response.val === presence
39
+                ) {
40
+                    matchingProfiles.push(profile)
41
+                }
42
+            }
43
+        }
44
+        return matchingProfiles
45
+    }
40 46
 
41
-module.exports = {
42
-    byProfileType,
43
-    byNullZip,
44
-    byMaxDistance,
45
-    byDuration,
46
-    byPresence,
47
-    byCertifications,
48
-}
47
+    byDuration(profileList, duration) {
48
+        const matchingProfiles = []
49
+        for (const profile of profileList) {
50
+            for (const response of profile.responses) {
51
+                if (
52
+                    response.response_key_id === 14 &&
53
+                    response.val === duration
54
+                ) {
55
+                    matchingProfiles.push(profile)
56
+                }
57
+            }
58
+        }
59
+        return matchingProfiles
60
+    }
61
+
62
+    // TODO: Implement filtering by matching certification
63
+    // byCertifications(profileList, certifications) {
64
+    // return profileList.filter(profile => {
65
+    // return profile.certifications === certifications
66
+    // })
67
+    // }
68
+}

+ 43
- 27
backend/lib/services/profile/index.js Visa fil

@@ -4,7 +4,8 @@ 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 filter = require('../filter')
7
+const Filter = require('../filter')
8
+const filter = new Filter()
8 9
 
9 10
 module.exports = class ProfileService extends Schmervice.Service {
10 11
     constructor(...args) {
@@ -251,7 +252,6 @@ module.exports = class ProfileService extends Schmervice.Service {
251 252
         certifications,
252 253
     ) {
253 254
         const { Profile } = this.server.models()
254
-
255 255
         await this._setScoreLookup()
256 256
 
257 257
         // Our User Profile to score for
@@ -275,10 +275,12 @@ module.exports = class ProfileService extends Schmervice.Service {
275 275
             distanceUnit,
276 276
             userZip,
277 277
         )
278
-        matchPool = filter.byMaxDistance(matchPool, maxDistance)
278
+
279
+        matchPool = filter.byDistance(matchPool, maxDistance)
279 280
         matchPool = filter.byDuration(matchPool, duration)
280 281
         matchPool = filter.byPresence(matchPool, presence)
281
-        matchPool = filter.byCertifications(matchPool, certifications)
282
+        // TODO: Incorporate filtering by certifications (see filter.js)
283
+        // matchPool = filter.byCertifications(matchPool, certifications)
282 284
 
283 285
         const scoredProfilesWithDistance = scoring.scoreAll(
284 286
             matchPool,
@@ -292,12 +294,11 @@ module.exports = class ProfileService extends Schmervice.Service {
292 294
     }
293 295
 
294 296
     async calcProfileDistances(matchPool, distanceUnit, userZip) {
295
-        await Promise.all(
297
+        const returnVal = await Promise.all(
296 298
             matchPool.map(async profile => {
297 299
                 const targetZip = zipcoder.getZipCodeFromProfile(profile)
298 300
                 if (!userZip || !targetZip)
299 301
                     return { ...profile, distance: [9999, distanceUnit] }
300
-
301 302
                 const distance = await this._compareDistance(
302 303
                     userZip,
303 304
                     targetZip,
@@ -309,6 +310,7 @@ module.exports = class ProfileService extends Schmervice.Service {
309 310
                 }
310 311
             }),
311 312
         )
313
+        return returnVal
312 314
     }
313 315
 
314 316
     /**
@@ -323,11 +325,14 @@ module.exports = class ProfileService extends Schmervice.Service {
323 325
             parseInt(zipCode),
324 326
         )
325 327
         if (!zipInfo) {
326
-            console.error('zip:', zipCode)
327
-        }
328
-        return {
329
-            latitude: parseFloat(zipInfo.latitude),
330
-            longitude: parseFloat(zipInfo.longitude),
328
+            throw new Error(
329
+                `ERROR :=> no zipInfo found for zipCode: ${zipCode}`,
330
+            )
331
+        } else {
332
+            return {
333
+                latitude: parseFloat(zipInfo.latitude),
334
+                longitude: parseFloat(zipInfo.longitude),
335
+            }
331 336
         }
332 337
     }
333 338
     /**
@@ -338,7 +343,13 @@ module.exports = class ProfileService extends Schmervice.Service {
338 343
      * @param {number} distance in miles
339 344
      */
340 345
     async _compareDistance(start_zip, end_zip, distanceUnit) {
341
-        if (!start_zip || !end_zip || isNaN(start_zip) || isNaN(end_zip)) return
346
+        if (
347
+            !start_zip ||
348
+            !end_zip ||
349
+            Number.isNaN(start_zip) ||
350
+            Number.isNaN(end_zip)
351
+        )
352
+            return
342 353
         const start = await this._latLonForZip(start_zip)
343 354
         const end = await this._latLonForZip(end_zip)
344 355
         return haversine(start, end, { unit: distanceUnit })
@@ -353,21 +364,26 @@ module.exports = class ProfileService extends Schmervice.Service {
353 364
     async getTagsFor(profileId, groupingId, category) {
354 365
         const { TagAssociation } = this.server.models()
355 366
         await this._setTagLookup()
356
-        let associations = groupingId
357
-            ? await TagAssociation.query()
358
-                  .where('grouping_id', groupingId)
359
-                  .andWhere('profile_id', profileId)
360
-            : await TagAssociation.query().andWhere('profile_id', profileId)
361
-        return associations
362
-            .map(assoc => ({
363
-                ...assoc,
364
-                tag: this.tagLookup[assoc.tag_id],
365
-            }))
366
-            .filter(tagWithAssoc => {
367
-                return category
368
-                    ? tagWithAssoc.tag.tag_category == category
369
-                    : true
370
-            })
367
+        let associations = []
368
+        if (!profileId.length || !groupingId.length) {
369
+            return associations
370
+        } else {
371
+            associations = groupingId
372
+                ? await TagAssociation.query()
373
+                      .where('grouping_id', groupingId)
374
+                      .andWhere('profile_id', profileId)
375
+                : await TagAssociation.query().andWhere('profile_id', profileId)
376
+            return associations
377
+                .map(assoc => ({
378
+                    ...assoc,
379
+                    tag: this.tagLookup[assoc.tag_id],
380
+                }))
381
+                .filter(tagWithAssoc => {
382
+                    return category
383
+                        ? tagWithAssoc.tag.tag_category == category
384
+                        : true
385
+                })
386
+        }
371 387
     }
372 388
 
373 389
     /**

+ 4
- 4
frontend/src/components/ProfileCard.vue Visa fil

@@ -101,7 +101,7 @@ const onTab = tabIndex => {
101 101
  * for both profileId and targetId
102 102
  */
103 103
 const onPair = async () => {
104
-    currentProfile._loading = true
104
+    currentProfile._loading.value = true
105 105
     const profileId = currentProfile.id.value
106 106
     const targetId = props.card.pid
107 107
     await postMembershipByProfileId({
@@ -110,7 +110,7 @@ const onPair = async () => {
110 110
     })
111 111
     await currentProfile.updateQueue(profileId, targetId, false)
112 112
     await currentProfile.getGroupings()
113
-    currentProfile._loading = false
113
+    currentProfile._loading.value = false
114 114
 
115 115
     let goToRoute = { name: 'HomeView' }
116 116
     router.push(goToRoute)
@@ -121,13 +121,13 @@ const onPair = async () => {
121 121
  * and forward back home
122 122
  */
123 123
 const onPass = async () => {
124
-    currentProfile._loading = true
124
+    currentProfile._loading.value = true
125 125
     await currentProfile.updateQueue(
126 126
         currentProfile.id.value,
127 127
         props.card.pid,
128 128
         true,
129 129
     )
130
-    currentProfile._loading = false
130
+    currentProfile._loading.value = false
131 131
 
132 132
     let goToRoute = { name: 'HomeView' }
133 133
     router.push(goToRoute)

+ 32
- 1
frontend/src/components/onboarding/Auth.vue Visa fil

@@ -8,6 +8,7 @@
8 8
 import { authenticator } from '../../services/auth.service.js'
9 9
 import { createProfileForUserId } from '../../services/profile.service'
10 10
 import { signupUser } from '../../services/user.service.js'
11
+import { scoreSurveyByProfileId } from '@/services'
11 12
 
12 13
 export default {
13 14
     name: 'Auth',
@@ -81,7 +82,37 @@ export default {
81 82
         },
82 83
         async createProfileForNewUser(userId, responses) {
83 84
             try {
84
-                await createProfileForUserId(userId, responses)
85
+                const newProfileForNewUser = await createProfileForUserId(
86
+                    userId,
87
+                    responses,
88
+                )
89
+                if (!newProfileForNewUser)
90
+                    throw Error(
91
+                        `ERROR: Unable to create newProfile for userId: ${userId}`,
92
+                    )
93
+
94
+                // NOTE: Populates matchQueue table with bare bone
95
+                // minimum filtered results of possible matches
96
+                // Based off of initial survey answers
97
+                const createdProfileId = newProfileForNewUser.profile_id
98
+                const maxDistance = this.responses
99
+                    .find(response => {
100
+                        return response.response_key_id === 19
101
+                    })
102
+                    .val.split(' ')[0]
103
+                const presence = this.responses.find(response => {
104
+                    return response.response_key_id === 15
105
+                }).val
106
+
107
+                // NOTE: duration hard coded for now as bare bones
108
+                // survey doesn't have duration as one of its steps...
109
+                const duration = 'full-time'
110
+                await scoreSurveyByProfileId(
111
+                    createdProfileId,
112
+                    maxDistance,
113
+                    duration,
114
+                    presence,
115
+                )
85 116
             } catch (err) {
86 117
                 throw new Error(err)
87 118
             }

+ 1
- 1
frontend/src/router/guards.js Visa fil

@@ -51,6 +51,6 @@ const checkLoginStatus = async (destination, nextCb) => {
51 51
     } else {
52 52
         nextCb()
53 53
     }
54
-        }
54
+}
55 55
 
56 56
 export { checkLoginStatus }

+ 0
- 3
frontend/src/services/auth.service.js Visa fil

@@ -1,9 +1,6 @@
1 1
 import { db } from '../utils/db.js'
2 2
 
3 3
 class Authenticator {
4
-    constructor() {
5
-        this.currentUser = null
6
-    }
7 4
     async sendEmail(answered) {
8 5
         return await db.post('/user/send-email/', answered)
9 6
     }

+ 11
- 3
frontend/src/views/OnboardingView.vue Visa fil

@@ -29,7 +29,11 @@ main.view--onboarding
29 29
             p(v-if='currentStep != 0') You have completed: {{ currentStep }} / {{ survey?.steps?.length }} survey steps
30 30
 
31 31
     article(v-else)
32
-        SurveyCompleteView(:answers='answered' :surveySteps='survey.steps' :responses='responses')
32
+        SurveyCompleteView(
33
+            :answers='answered'
34
+            :responses='responses'
35
+            :surveySteps='survey.steps'
36
+        )
33 37
 </template>
34 38
 
35 39
 <script>
@@ -53,10 +57,13 @@ export default {
53 57
         invalidResponse: false,
54 58
     }),
55 59
     async created() {
60
+        // TODO: Troubleshoot bug where not all responses are returned at SurveyCompleteView
61
+        console.log('currentProfile :=>', currentProfile)
56 62
         this.survey = await surveyFactory.createSurvey()
57 63
         try {
58
-            const sessionData =
59
-                await authenticator.verifySessionCookie('siimee_session')
64
+            const sessionData = await authenticator.verifySessionCookie(
65
+                'siimee_session',
66
+            )
60 67
             if (sessionData) {
61 68
                 this.responses = this.formatResponses(
62 69
                     currentProfile._profile.responses,
@@ -85,6 +92,7 @@ export default {
85 92
             })
86 93
         },
87 94
         async updateAnswers(payload) {
95
+            console.log('this.survey.steps :=>', this.survey.steps)
88 96
             if (payload) {
89 97
                 const k = payload.question.survey_stage
90 98
                 this.answered[k] = payload.input

+ 59
- 3
frontend/src/views/SurveyCompleteView.vue Visa fil

@@ -1,13 +1,15 @@
1 1
 <template lang="pug">
2 2
 main.view--surveycomplete
3
-    article(style='display: flex; flex-direction: column; align-items: center; text-align: center;')
3
+    article(
4
+        style='display: flex; flex-direction: column; align-items: center; text-align: center'
5
+    )
4 6
         h2 Thanks for Completing Our Survey!!
5 7
         h1 Please review your answers and let us know if you need to change anything.
6 8
         div(v-for='response in responses')
7
-            p Your {{ response.stage }}: 
9
+            p Your {{ response.stage }}:
8 10
             p {{ response.val }}
9 11
             br
10
-        div.survey-spacer
12
+        .survey-spacer
11 13
         div(v-for='aspectResponse in aspectResponses')
12 14
             p {{ aspectResponse.question }} :
13 15
             br
@@ -65,6 +67,7 @@ export default {
65 67
                 }
66 68
             })
67 69
         },
70
+        // Grabs all responses to questions that are NOT aspect questions
68 71
         grabResponsesFromProfile(aspectQuestions) {
69 72
             const aspectQuestionsKeys = Object.keys(aspectQuestions).map(Number)
70 73
             const responses = currentProfile._profile.responses
@@ -106,6 +109,59 @@ export default {
106 109
         },
107 110
         // changeAnswers() {},
108 111
     },
112
+    /*
113
+    NOTE: Incomplete logic for adjusting matchQueue results based
114
+    off of further completion of survey, commented out for now as
115
+    to not overwrite methods
116
+    methods: {
117
+        changeAnswers(){
118
+            console.log('change answers')
119
+        },
120
+
121
+        async finalSubmit() {
122
+            // separate user info from responses
123
+            const [user, survey] = this._separateUserInfoFromResponses(
124
+                this.answers,
125
+            )
126
+
127
+            // create user
128
+            const createdUser = await signUpUser(user)
129
+            if (!createdUser) return
130
+
131
+            // create profile
132
+            const userProfile = await createProfileForUserId(
133
+                createdUser.user_id,
134
+                survey,
135
+            )
136
+            if (!userProfile) return
137
+<<<<<<< HEAD
138
+
139
+=======
140
+>>>>>>> 9966fff (:construction: Continued filtering logic for initial survey answers)
141
+            this._setLoginForProfile(userProfile)
142
+
143
+            this.$router.push({ name: 'HomeView' })
144
+        },
145
+
146
+        // TODO write logic to parse answers
147
+        _separateUserInfoFromResponses(answers) {
148
+            return ['', '']
149
+        },
150
+
151
+        async _setLoginForProfile(profile) {
152
+            const currentId = currentProfile.login(profile.profile_id)
153
+            if (currentId && profile.responses.length) {
154
+                currentProfile.setResponses(profile.responses)
155
+            }
156
+            if (!currentProfile.isComplete) {
157
+                console.error(
158
+                    `Profile ${currentProfile.id} is incomplete. Please make sure all survey questions have been answered.`,
159
+                )
160
+                return
161
+            }
162
+        }
163
+    }
164
+    */
109 165
 }
110 166
 </script>
111 167
 <style>

Laddar…
Avbryt
Spara