|
|
@@ -8,12 +8,18 @@ import { db } from '../utils/db.js'
|
|
8
|
8
|
* @returns {array} instantiated Profile objects (see: /entites/profile)
|
|
9
|
9
|
*/
|
|
10
|
10
|
const fetchQuestions = async () => {
|
|
11
|
|
- const questions = await db.get(`/survey/questions`)
|
|
12
|
|
- // Add responses to match the format from the survery factory
|
|
13
|
|
- return questions.map(q => {
|
|
14
|
|
- q.responses = !q.responses ? [] : q.responses
|
|
15
|
|
- return q
|
|
16
|
|
- })
|
|
|
11
|
+ let withResponses
|
|
|
12
|
+ try {
|
|
|
13
|
+ const questions = await db.get(`/survey/questions`)
|
|
|
14
|
+ // Add responses to match the format from the survery factory
|
|
|
15
|
+ withResponses = questions.map(q => {
|
|
|
16
|
+ q.responses = !q.responses ? [] : q.responses
|
|
|
17
|
+ return q
|
|
|
18
|
+ })
|
|
|
19
|
+ } catch (error) {
|
|
|
20
|
+ console.error(`[Survey Service]: ${error}\nquestions: ${withResponses}`)
|
|
|
21
|
+ }
|
|
|
22
|
+ return withResponses
|
|
17
|
23
|
}
|
|
18
|
24
|
|
|
19
|
25
|
const updateSurveyByProfileId = async (surveyResponses, profileId) => {
|
|
|
@@ -32,22 +38,6 @@ const updateSurveyByProfileId = async (surveyResponses, profileId) => {
|
|
32
|
38
|
})
|
|
33
|
39
|
}
|
|
34
|
40
|
|
|
35
|
|
-// const updateSurveyByProfileId = async (surveyResponses, profileId) => {
|
|
36
|
|
-// surveyResponses.forEach(responseKeyIdwithVal => {
|
|
37
|
|
-// const keyId = responseKeyIdwithVal.response_key_id
|
|
38
|
|
-// const val = responseKeyIdwithVal.val
|
|
39
|
|
-// // PATCH
|
|
40
|
|
-// db.patch(`/profile/${profileId}/update/${keyId}`, [
|
|
41
|
|
-// {
|
|
42
|
|
-// response_id: 2,
|
|
43
|
|
-// profile_id: profileId,
|
|
44
|
|
-// response_key_id: keyId,
|
|
45
|
|
-// val: val,
|
|
46
|
|
-// },
|
|
47
|
|
-// ])
|
|
48
|
|
-// })
|
|
49
|
|
-// }
|
|
50
|
|
-
|
|
51
|
41
|
const scoreSurveyByProfileId = async (profileId, maxDistance = 99) => {
|
|
52
|
42
|
const scoreSurvey = await db.get(
|
|
53
|
43
|
`/profile/${profileId}/score?max_distance=${maxDistance}`,
|