Selaa lähdekoodia

:recycle: mapping input to score array | saving email | tweaking guard to use survey

tags/0.0.1
J 4 vuotta sitten
vanhempi
commit
679531049d

+ 16
- 16
backend/db/data-generator/mock.js Näytä tiedosto

@@ -95,98 +95,98 @@ module.exports = {
95 95
             response_key_id: 1,
96 96
             response_key_category: 'grit',
97 97
             response_key_prompt: 'can you power through adversity',
98
-            response_key_description: null,
98
+            response_key_description: 'first round draft scoring question',
99 99
         },
100 100
         {
101 101
             response_key_id: 2,
102 102
             response_key_category: 'openness',
103 103
             response_key_prompt: 'are you open with your emotions with everyone',
104
-            response_key_description: null,
104
+            response_key_description: 'first round draft scoring question',
105 105
         },
106 106
         {
107 107
             response_key_id: 3,
108 108
             response_key_category: 'bravery',
109 109
             response_key_prompt: 'do you speak-up when you feel something is wrong',
110
-            response_key_description: null,
110
+            response_key_description: 'first round draft scoring question',
111 111
         },
112 112
         {
113 113
             response_key_id: 4,
114 114
             response_key_category: 'empathy',
115 115
             response_key_prompt:
116 116
                 'do you stop to help others when they are struggling',
117
-            response_key_description: null,
117
+            response_key_description: 'first round draft scoring question',
118 118
         },
119 119
         {
120 120
             response_key_id: 5,
121 121
             response_key_category: 'honesty',
122 122
             response_key_prompt: 'when telling a story do you exaggerate for dramatic effect',
123
-            response_key_description: null,
123
+            response_key_description: 'first round draft scoring question',
124 124
         },
125 125
         {
126 126
             response_key_id: 6,
127 127
             response_key_category: 'respect',
128 128
             response_key_prompt: 'do you treat difficult people as well as you treat your close friends',
129
-            response_key_description: null,
129
+            response_key_description: 'first round draft scoring question',
130 130
         },
131 131
         {
132 132
             response_key_id: 7,
133 133
             response_key_category: 'profile',
134 134
             response_key_prompt: 'zipcode',
135
-            response_key_description: null,
135
+            response_key_description: 'required for distance calculations',
136 136
         },
137 137
         {
138 138
             response_key_id: 8,
139 139
             response_key_category: 'profile',
140 140
             response_key_prompt: 'image',
141
-            response_key_description: null,
141
+            response_key_description: 'required for profile pictures',
142 142
         },
143 143
         {
144 144
             response_key_id: 9,
145 145
             response_key_category: 'profile',
146 146
             response_key_prompt: 'language',
147
-            response_key_description: null,
147
+            response_key_description: 'programming and spoken language preference',
148 148
         },
149 149
         {
150 150
             response_key_id: 10,
151 151
             response_key_category: 'profile',
152 152
             response_key_prompt: 'duration',
153
-            response_key_description: null,
153
+            response_key_description: 'duration preference for hours able to dedicate to work',
154 154
         },
155 155
         {
156 156
             response_key_id: 11,
157 157
             response_key_category: 'profile',
158 158
             response_key_prompt: 'presence',
159
-            response_key_description: null,
159
+            response_key_description: 'location preference for where work happens',
160 160
         },
161 161
         {
162 162
             response_key_id: 12,
163 163
             response_key_category: 'profile',
164 164
             response_key_prompt: 'blurb',
165
-            response_key_description: null,
165
+            response_key_description: 'required for profile description',
166 166
         },
167 167
         {
168 168
             response_key_id: 13,
169 169
             response_key_category: 'profile',
170 170
             response_key_prompt: 'urgency',
171
-            response_key_description: null,
171
+            response_key_description: 'urgency for when work is required',
172 172
         },
173 173
         {
174 174
             response_key_id: 14,
175 175
             response_key_category: 'profile',
176 176
             response_key_prompt: 'role',
177
-            response_key_description: null,
177
+            response_key_description: 'current and desired role',
178 178
         },
179 179
         {
180 180
             response_key_id: 15,
181 181
             response_key_category: 'profile',
182 182
             response_key_prompt: 'pronouns',
183
-            response_key_description: null,
183
+            response_key_description: 'required for profile pronouns',
184 184
         },
185 185
         {
186 186
             response_key_id: 16,
187 187
             response_key_category: 'profile',
188 188
             response_key_prompt: 'distance',
189
-            response_key_description: null,
189
+            response_key_description: 'preference for commuting distance cutoff',
190 190
         },
191 191
     ],
192 192
     responses: [],

+ 22
- 9
backend/lib/services/profile.js Näytä tiedosto

@@ -1,8 +1,9 @@
1 1
 const Schmervice = require('@hapipal/schmervice')
2 2
 const haversine = require('haversine')
3
+const config = require('../../db/data-generator/config.json')
3 4
 
4 5
 // Keys that are profile data responses
5
-const _TEMP_RES_KEYS = [8, 9, 10, 11, 12]
6
+const _TEMP_RES_KEYS = [1, 2, 3, 4, 5, 6]
6 7
 const _ZIPCODEKEY = 7
7 8
 const scoreResponses = (seeker, potentialMatch, prescoreLookup) => {
8 9
     if (seeker.responses.length != potentialMatch.responses.length)
@@ -11,10 +12,10 @@ const scoreResponses = (seeker, potentialMatch, prescoreLookup) => {
11 12
         }
12 13
 
13 14
     const aRes = seeker.responses.filter(
14
-        res => !_TEMP_RES_KEYS.includes(res.response_key_id),
15
+        res => _TEMP_RES_KEYS.includes(res.response_key_id)
15 16
     )
16 17
     const bRes = potentialMatch.responses.filter(
17
-        res => !_TEMP_RES_KEYS.includes(res.response_key_id),
18
+        res => _TEMP_RES_KEYS.includes(res.response_key_id)
18 19
     )
19 20
 
20 21
     const composite = []
@@ -129,7 +130,6 @@ module.exports = class ProfileService extends Schmervice.Service {
129 130
         super(...args)
130 131
         this.scoreLookup = {}
131 132
         this.tagLookup = {}
132
-
133 133
         // this.responseKeyLookup = ResponseKey.query()
134 134
     }
135 135
     async _setScoreLookup() {
@@ -309,16 +309,16 @@ module.exports = class ProfileService extends Schmervice.Service {
309 309
         let allResponses = await Response.query().where({
310 310
             profile_id: profileId,
311 311
         })
312
+
313
+        // Delete matches
314
+        // ?:Maybe bad idea
312 315
         const matchingResponses = allResponses.filter(
313 316
             response =>
314 317
                 response.response_key_id == responseToSave.response_key_id,
315 318
         )
316
-
317
-        // Delete matches
318
-        // ?:Maybe bad idea
319 319
         if (matchingResponses.length > 0) {
320 320
             const alreadyAnswered = matchingResponses.map(
321
-                matchingRes => matchingRes.response_key_id,
321
+                matchingRes => matchingRes.response_key_id
322 322
             )
323 323
             await Response.query()
324 324
                 .where({ profile_id: profileId })
@@ -326,7 +326,20 @@ module.exports = class ProfileService extends Schmervice.Service {
326 326
                 .whereIn('response_key_id', alreadyAnswered)
327 327
         }
328 328
 
329
-        await Response.query().insert(responseToSave)
329
+        /**
330
+         * Convert indexes to actual score values
331
+         * Using using the input and converting to index
332
+         * of the generated possible prescore array in config
333
+         */ 
334
+        let convertedResponse = responseToSave
335
+        if(_TEMP_RES_KEYS.includes(responseToSave.response_key_id)) {
336
+            // Convert -3 to 0, 0 to 3, 3 to 6
337
+            const offset = (config.scoreVals.length - 1) / 2
338
+            const indexFromInput = parseInt(responseToSave.val) + offset
339
+            convertedResponse.val = config.scoreVals[indexFromInput]
340
+        }
341
+
342
+        await Response.query().insert(convertedResponse)
330 343
         return allResponses
331 344
     }
332 345
 

+ 2
- 2
frontend/src/components/ProfileCardList.vue Näytä tiedosto

@@ -9,7 +9,7 @@ section.profile_card_list.w-full
9 9
             v-for="(profile, i) in loadedProfiles"
10 10
             :style="{ 'z-index': 1000-i }"
11 11
         )
12
-            .card.b-solid.rounded.p-0.bg-cover.randomize(
12
+            .card.b-solid.rounded.bg-cover.randomize(
13 13
                 :style="{ 'background-image': `url(${profile.avatar})`, 'top': `${randomize(10)}px`, 'right': `${randomize(20)}px`, 'transform': `rotate(${randomize(7)}deg)` }"
14 14
             )
15 15
                 .card__content
@@ -27,7 +27,7 @@ section.profile_card_list.w-full
27 27
             :key="profile.pid"
28 28
             v-for="(profile, i) in loadedProfiles"
29 29
         )
30
-                .card.b-solid.rounded.p-0.bg-cover(
30
+                .card.b-solid.rounded.bg-cover(
31 31
                     :style="{ 'background-image': `url(${profile.avatar})` }"
32 32
                 )
33 33
                 .card__content

+ 2
- 1
frontend/src/router/guards.js Näytä tiedosto

@@ -6,11 +6,12 @@ const checkLoginStatus = (destination, nextCb) => {
6 6
     console.warn('currentProfile completed:', currentProfile.isComplete())
7 7
     if (
8 8
         destination.meta.requiresCompleteProfile &&
9
-        currentProfile.isLoggedIn() &&
9
+        !currentProfile.isLoggedIn() &&
10 10
         !currentProfile.isComplete() 
11 11
     ) {
12 12
         nextCb('survey')
13 13
     } else if(
14
+        destination.meta.requiresCompleteProfile &&
14 15
         destination.meta.requiresAuth &&
15 16
         !currentProfile.isLoggedIn()
16 17
     ) {

+ 1
- 1
frontend/src/services/login.service.js Näytä tiedosto

@@ -24,7 +24,7 @@ class Login {
24 24
         return this.id.value != null
25 25
     }
26 26
     isComplete() {
27
-        return this.responses.length == surveyFactory.questions.length
27
+        return this.responses.length == surveyFactory.questionsFromDb.length && surveyFactory.questionsFromDb.length > 0
28 28
     }
29 29
     hasResponses() {
30 30
         return this.responses.length && this.responses.length > 0

+ 3
- 0
frontend/src/utils/lang.js Näytä tiedosto

@@ -1,6 +1,7 @@
1 1
 const DELIMITER = '_'
2 2
 
3 3
 const stepToComponentMap = {
4
+    email: 'InputString',
4 5
     name: 'InputString',
5 6
     seeking: 'ButtonChoice',
6 7
     urgency: 'ButtonChoice',
@@ -18,6 +19,7 @@ const stepToComponentMap = {
18 19
 // TODO: Combine these two
19 20
 const allSteps = {
20 21
     usa: {
22
+        email: 'email',
21 23
         name: 'name',
22 24
         pronouns: 'pronouns',
23 25
         seeking: 'seeking',
@@ -50,6 +52,7 @@ const allResponses = {
50 52
 
51 53
 const possible = {}
52 54
 possible.usa = {
55
+    email: [],
53 56
     name: [],
54 57
     seeking: ['position', 'candidate'],
55 58
     language: [

+ 8
- 4
frontend/src/utils/survey.js Näytä tiedosto

@@ -25,14 +25,18 @@ class SurveyFactory {
25 25
         return [...stepsInCommon, ...unseen]
26 26
     }
27 27
     async getQuestions() {
28
-        this.questionsFromDb = await fetchQuestions()
28
+        try {
29
+            this.questionsFromDb = await fetchQuestions()
30
+            return this.questionsFromDb
31
+        } catch(err) {
32
+            console.error(err)
33
+        }
29 34
     }
30 35
     async createSurvey(langFile, roleTree) {
31 36
         if(!this.questionsFromDb.length) {
32
-            console.error('Attempted to create a survey before getting questions')
33
-            await this.getQuestions()
37
+            const res = await this.getQuestions()
38
+            console.warn(`Attempted to create a survey before getting questions: retrieved ${res.length} questions`)
34 39
         }
35
-
36 40
         const steps = this._setSteps(langFile)
37 41
         return new Survey(steps, roleTree)
38 42
     }

+ 2
- 1
frontend/src/views/SurveyView.vue Näytä tiedosto

@@ -74,6 +74,7 @@ export default {
74 74
             slideDuration: 1200,
75 75
             step: 0,
76 76
             profile: {
77
+                email: '',
77 78
                 name: '',
78 79
                 seeking: '',
79 80
                 urgency: '',
@@ -110,7 +111,7 @@ export default {
110 111
     },
111 112
     async created() {
112 113
         /**
113
-         * Before this ever gets called, surveyFactory.questions
114
+         * Before this ever gets called, surveyFactory.questionsFromDb
114 115
          * must be set by App.created()
115 116
          */
116 117
         this.validSurvey = await surveyFactory.createSurvey(

Loading…
Peruuta
Tallenna