Преглед на файлове

:recycle: more tweaks to mock questions | making responses work with frontend survey questions | lang file | widget Map

tags/0.0.1
J преди 4 години
родител
ревизия
d3213c6848

+ 12
- 0
backend/db/data-generator/mock.js Целия файл

@@ -119,6 +119,18 @@ module.exports = {
119 119
             response_key_prompt: 'blurb',
120 120
             response_key_description: null,
121 121
         },
122
+        {
123
+            response_key_id: 13,
124
+            response_key_category: 'profile',
125
+            response_key_prompt: 'urgency',
126
+            response_key_description: null,
127
+        },
128
+        {
129
+            response_key_id: 14,
130
+            response_key_category: 'profile',
131
+            response_key_prompt: 'role',
132
+            response_key_description: null,
133
+        },
122 134
     ],
123 135
     responses: [],
124 136
     memberships: [],

+ 1
- 1
frontend/src/entities/survey/survey.js Целия файл

@@ -10,7 +10,7 @@ class Survey extends _baseRecord {
10 10
 
11 11
         /**  Fields */
12 12
         this.steps = [
13
-            ...Object.values(questionSteps),
13
+            ...questionSteps
14 14
         ] // ! required
15 15
         
16 16
         return this

+ 7
- 9
frontend/src/entities/survey/survey.schema.js Целия файл

@@ -18,15 +18,13 @@ const surveySchema = {
18 18
 
19 19
         /** Survey fields */
20 20
         steps: Joi.array().items(
21
-            Joi.array().items(
22
-                Joi.object({
23
-                    id: Joi.number(),
24
-                    type: Joi.string(),
25
-                    question: Joi.string(),
26
-                    // TODO: specify responses to be array or null later
27
-                    responses: Joi.any(),
28
-                })
29
-            )
21
+            Joi.object({
22
+                id: Joi.number(),
23
+                type: Joi.string(),
24
+                question: Joi.string(),
25
+                // TODO: specify responses to be array or null later
26
+                responses: Joi.any(),
27
+            })
30 28
         ).required(),
31 29
     }),
32 30
     /** fields required before saving */

+ 3
- 40
frontend/src/services/survey.service.js Целия файл

@@ -1,5 +1,4 @@
1 1
 import { db } from '../utils/db'
2
-import { Survey } from '../entities/survey'
3 2
 
4 3
 /**
5 4
  * Get Survey for first time profile creation from the database and
@@ -8,44 +7,8 @@ import { Survey } from '../entities/survey'
8 7
  * @param {number} profileId
9 8
  * @returns {array} instantiated Profile objects (see: /entites/profile)
10 9
  */
11
-const fetchSurveyByProfileId = async profileId => {
12
-    const myquestions = await db.get(`/survey/questions`)
13
-    const allsteps = {}
14
-    const questionsPerStep = 3
15
-    const stepsNeeded = Math.ceil(myquestions.length / questionsPerStep)
16
-
17
-    // Create the steps needed inside allsteps
18
-    for (let i = 1; i <= stepsNeeded; i++) {
19
-        allsteps[`step-${i}`] = []
20
-    }
21
-
22
-    // Add the questions into each step, dividing into questionsPerStep
23
-    for (let i = 0; i < myquestions.length; i++) {
24
-        const question = myquestions[i]
25
-
26
-        // Set the input type based on category
27
-        const type =
28
-            question.response_key_category != 'profile'
29
-                ? 'input-slide'
30
-                : 'input-string'
31
-
32
-        // Reformats myquestions into the format we want
33
-        const reformatted = {
34
-            id: question.response_key_id,
35
-            type,
36
-            question: question.response_key_prompt,
37
-            responses: null,
38
-            description: question.response_key_description,
39
-            category: question.response_key_category,
40
-        }
41
-        for (let n = 1; n <= stepsNeeded; n++) {
42
-            if (i >= questionsPerStep * (n - 1) && i < questionsPerStep * n) {
43
-                allsteps[`step-${n}`].push(reformatted)
44
-            }
45
-        }
46
-    }
47
-    const mysurvey = new Survey(allsteps)
48
-    return mysurvey
10
+const fetchQuestionsByProfileId = async profileId => {
11
+    return await db.get(`/survey/questions`)
49 12
 }
50 13
 
51 14
 const saveSurveyByProfileId = async (surveyResponses, profileId) => {
@@ -85,7 +48,7 @@ const scoreSurveyByProfileId = async (profileId, maxDistance) => {
85 48
 }
86 49
 
87 50
 export {
88
-    fetchSurveyByProfileId,
51
+    fetchQuestionsByProfileId,
89 52
     saveSurveyByProfileId,
90 53
     updateSurveyByProfileId,
91 54
     scoreSurveyByProfileId,

+ 4
- 1
frontend/src/utils/index.js Целия файл

@@ -2,6 +2,8 @@ import Joi from 'joi'
2 2
 import { Connector } from './db'
3 3
 import { Login } from './login'
4 4
 import { Authenticator } from './auth'
5
+import { SurveyFactory } from './survey'
6
+import { possible } from './lang'
5 7
 
6 8
 const api = new Connector('kittens')
7 9
 
@@ -18,5 +20,6 @@ const makeKebob = input => {
18 20
 
19 21
 const loginHandler = new Login()
20 22
 const authHandler = new Authenticator()
23
+const surveyFactory = new SurveyFactory(possible['usa'])
21 24
 
22
-export { api, validatorMapping, loginHandler, authHandler, makeKebob }
25
+export { api, validatorMapping, loginHandler, authHandler, surveyFactory, makeKebob }

+ 96
- 0
frontend/src/utils/lang.js Целия файл

@@ -0,0 +1,96 @@
1
+const DELIMITER = '_'
2
+
3
+const stepToComponentMap = {
4
+    name: 'InputString',
5
+    seeking: 'ButtonMulti',
6
+    urgency: 'ButtonChoice',
7
+    distance: 'ButtonChoice',
8
+    duration: 'ButtonChoice',
9
+    language: 'ButtonMulti',
10
+}
11
+
12
+const allSteps = {
13
+    usa: {
14
+        name: 'name',
15
+        seeking: 'seeking',
16
+        urgency: 'urgency',
17
+        distance: 'distance',
18
+        duration: 'duration',
19
+        language: 'language',
20
+    }
21
+}
22
+
23
+const possible = {}
24
+possible.usa = {
25
+    name: [],
26
+    seeking: ['position', 'candidate'],
27
+    language: [
28
+        'javascript',
29
+        'python',
30
+        'c#',
31
+        'c++',
32
+        'go',
33
+        'java',
34
+        'ruby',
35
+        'html',
36
+        'css',
37
+    ],
38
+    // key 13
39
+    urgency: [
40
+        'actively_looking',
41
+        'open_to_the_right_opportunity',
42
+        'just_browsing',
43
+        'networking',
44
+    ],
45
+    // key 10
46
+    distance: [
47
+        'remote',
48
+        'in_person',
49
+        'hybrid',
50
+        'flexible'
51
+    ],
52
+    // key 11
53
+    duration: [
54
+        'full-time',
55
+        'part-time',
56
+        'contract',
57
+        'flexible',
58
+    ],
59
+    // Everything else concats under role, key: 14
60
+    experience_levels: [
61
+        'associate',
62
+        'junior',
63
+        'mid-level',
64
+        'senior',
65
+        'staff',
66
+        'chief_of',
67
+        'director_of',
68
+    ],
69
+    roles: {
70
+        type: [
71
+            'back-end',
72
+            'database',
73
+            'front-end',
74
+            'full-stack',
75
+            'qa',
76
+            'security',
77
+            'system',
78
+            'test',
79
+        ],
80
+        seeker: [
81
+            'administrator',
82
+            'analyst',
83
+            'architect',
84
+            'developer',
85
+            'engineer',
86
+            'manager',
87
+            'technician',
88
+        ],
89
+        provider: [
90
+            'hiring_manager',
91
+            'recruiter',
92
+        ]
93
+    },
94
+}
95
+
96
+export { allSteps, stepToComponentMap, possible }

+ 34
- 0
frontend/src/utils/survey.js Целия файл

@@ -0,0 +1,34 @@
1
+import { Survey } from '../entities'
2
+import { fetchQuestionsByProfileId } from '../services'
3
+
4
+class SurveyFactory {
5
+    constructor(responses) {
6
+        this.responsesByCategory = responses
7
+    }
8
+    async setSteps(langFile) {
9
+        const stepsToProcess = [...Object.values(langFile) ]
10
+        console.log(stepsToProcess)
11
+        const questions = await fetchQuestionsByProfileId()
12
+        const seenIds = []
13
+        const stepsInCommon = stepsToProcess.map(step => {
14
+            // Match question to step
15
+            const match = questions.filter(q => q.response_key_prompt == step)[0]
16
+            if(match) { seenIds.push(match.response_key_id) }
17
+            return {
18
+                response_key_category: match ? match.response_key_category: 'profile',
19
+                response_key_description: match ? match.response_key_description: null,
20
+                response_key_id: match ? match.response_key_id: null,
21
+                response_key_prompt: match ? match.response_key_prompt: step,
22
+                responses: this.responsesByCategory[step] ? this.responsesByCategory[step] : [] 
23
+            }
24
+        })
25
+        const unseen = questions.filter(q => !seenIds.includes(q.response_key_id))
26
+        return [...stepsInCommon, ...unseen]
27
+    }
28
+    async createSurvey(langFile) {
29
+        const steps = await this.setSteps(langFile)
30
+        return new Survey(steps)
31
+    }
32
+}
33
+
34
+export { SurveyFactory }

+ 24
- 16
frontend/src/views/Survey.vue Целия файл

@@ -3,6 +3,13 @@ main.f-col.start.w-full
3 3
     ButtonMulti
4 4
     //- ButtonChoice
5 5
     //- InputString
6
+    h5(v-if="profileQuestions.length" v-for="q in profileQuestions")
7
+        span(v-if="componentMap[q.response_key_prompt]") {{ componentMap[q.response_key_prompt] }}:
8
+        span(v-else) InputString:
9
+        span {{ q.response_key_prompt }} | 
10
+        span(v-if="q.responses")
11
+            button(v-for="resp in q.responses") {{ resp }}
12
+
6 13
     article.match.w-full
7 14
         ul.w-full
8 15
             li(v-if="step == 0")
@@ -105,23 +112,13 @@ main.f-col.start.w-full
105 112
 </template>
106 113
 
107 114
 <script>
115
+import { surveyFactory } from '../utils'
116
+import { allSteps, stepToComponentMap } from '../utils/lang'
108 117
 import SurveyForm from '../components/form.vue'
109
-import { fetchSurveyByProfileId } from '../services'
110 118
 import ButtonMulti from '../components/form/button-multi.vue'
111 119
 import ButtonChoice from '../components/form/button-choice.vue'
112 120
 import InputString from '../components/form/input-string.vue'
113 121
 
114
-const locations = ['remote', 'in_person']
115
-const roles = [
116
-    ['recruiter', 'hiring_manager'],
117
-    [
118
-        'junior_engineer',
119
-        'mid-level_engineer',
120
-        'senior_engineer',
121
-        'staff_engineer',
122
-    ],
123
-]
124
-
125 122
 export default {
126 123
     components: { SurveyForm, ButtonMulti, ButtonChoice, InputString },
127 124
     props: {
@@ -133,6 +130,7 @@ export default {
133 130
     data() {
134 131
         return {
135 132
             validSurvey: null,
133
+            componentMap: stepToComponentMap,
136 134
             step: 0,
137 135
             name: '',
138 136
             seeking: '',
@@ -143,6 +141,20 @@ export default {
143 141
             zipcode: '',
144 142
         }
145 143
     },
144
+    computed: {
145
+        profileQuestions() {
146
+            if(!this.validSurvey) return []
147
+            return this.validSurvey.steps.filter(step => step.response_key_category == 'profile')
148
+        },
149
+        priorityQuestions() {
150
+            if(!this.validSurvey) return []
151
+            return this.validSurvey.steps.filter(step => step.response_key_category != 'profile')
152
+        }
153
+    },
154
+    async created() {
155
+        this.validSurvey = await surveyFactory.createSurvey(allSteps['usa'])
156
+        console.log('profile:', this.profileQuestions)
157
+    },
146 158
     methods: {
147 159
         saveNext(val) {
148 160
             console.log(val)
@@ -150,10 +162,6 @@ export default {
150 162
             this.step++
151 163
         },
152 164
     },
153
-    async created() {
154
-        this.validSurvey = await fetchSurveyByProfileId(this.pid)
155
-        console.log('survey for:', this.validSurvey)
156
-    },
157 165
 }
158 166
 </script>
159 167
 

Loading…
Отказ
Запис