|
|
@@ -10,7 +10,7 @@ import { Survey } from '../entities/survey'
|
|
10
|
10
|
*/
|
|
11
|
11
|
const fetchSurveyByProfileId = async profileId => {
|
|
12
|
12
|
const myquestions = await db.get(`/survey/questions`)
|
|
13
|
|
- const allsteps = { }
|
|
|
13
|
+ const allsteps = {}
|
|
14
|
14
|
const questionsPerStep = 3
|
|
15
|
15
|
const stepsNeeded = Math.ceil(myquestions.length / questionsPerStep)
|
|
16
|
16
|
|
|
|
@@ -32,7 +32,7 @@ const fetchSurveyByProfileId = async profileId => {
|
|
32
|
32
|
category: question.response_key_category,
|
|
33
|
33
|
}
|
|
34
|
34
|
for (let n = 1; n <= stepsNeeded; n++) {
|
|
35
|
|
- if (i >=questionsPerStep*(n-1) && i < questionsPerStep*n) {
|
|
|
35
|
+ if (i >= questionsPerStep * (n - 1) && i < questionsPerStep * n) {
|
|
36
|
36
|
allsteps[`step-${n}`].push(reformatted)
|
|
37
|
37
|
}
|
|
38
|
38
|
}
|
|
|
@@ -43,34 +43,40 @@ const fetchSurveyByProfileId = async profileId => {
|
|
43
|
43
|
|
|
44
|
44
|
// TODO: separate to newSurvey vs updateSurvey
|
|
45
|
45
|
const saveSurveyByProfileID = async (surveyResponses, profileId) => {
|
|
46
|
|
- surveyResponses.forEach((responseKeyIdwithVal) => {
|
|
|
46
|
+ surveyResponses.forEach(responseKeyIdwithVal => {
|
|
47
|
47
|
const keyId = responseKeyIdwithVal.response_key_id
|
|
48
|
48
|
const val = responseKeyIdwithVal.val
|
|
49
|
|
- // POST
|
|
50
|
|
- const myresponses = db.post(`/${profileId}/respond?response_key_id=${keyId}&val=${val}`)
|
|
51
|
|
- return myresponses
|
|
|
49
|
+ console.log('saveSurvey keyId', keyId)
|
|
|
50
|
+ console.log('saveSurvey val', val)
|
|
|
51
|
+
|
|
|
52
|
+ // POST
|
|
|
53
|
+ // const myresponses = db.post(`/${profileId}/respond?response_key_id=${keyId}&val=${val}`)
|
|
|
54
|
+ // return myresponses
|
|
52
|
55
|
})
|
|
53
|
56
|
}
|
|
54
|
57
|
|
|
55
|
58
|
const updateSurveyByProfileId = async (surveyResponses, profileId) => {
|
|
56
|
|
- surveyResponses.forEach((responseKeyIdwithVal) => {
|
|
|
59
|
+ surveyResponses.forEach(responseKeyIdwithVal => {
|
|
57
|
60
|
const keyId = responseKeyIdwithVal.response_key_id
|
|
58
|
61
|
const val = responseKeyIdwithVal.val
|
|
59
|
|
- // PATCH
|
|
60
|
|
- // const myresponses = db.patch(`/profile/${profileId}/update/${keyId}`,
|
|
61
|
|
- // [
|
|
62
|
|
- // {
|
|
63
|
|
- // response_id: 2,
|
|
64
|
|
- // profile_id: profileId,
|
|
65
|
|
- // response_key_id: keyId,
|
|
66
|
|
- // val: val,
|
|
67
|
|
- // },
|
|
68
|
|
- // ]
|
|
69
|
|
- // )
|
|
|
62
|
+ console.log('saveSurvey keyId', keyId)
|
|
|
63
|
+ console.log('saveSurvey val', val)
|
|
|
64
|
+ // PATCH
|
|
|
65
|
+ // const myresponses = db.patch(`/profile/${profileId}/update/${keyId}`,
|
|
|
66
|
+ // [
|
|
|
67
|
+ // {
|
|
|
68
|
+ // response_id: 2,
|
|
|
69
|
+ // profile_id: profileId,
|
|
|
70
|
+ // response_key_id: keyId,
|
|
|
71
|
+ // val: val,
|
|
|
72
|
+ // },
|
|
|
73
|
+ // ]
|
|
|
74
|
+ // )
|
|
|
75
|
+ })
|
|
70
|
76
|
}
|
|
71
|
77
|
|
|
72
|
78
|
export {
|
|
73
|
79
|
fetchSurveyByProfileId,
|
|
74
|
80
|
saveSurveyByProfileID,
|
|
75
|
81
|
updateSurveyByProfileId,
|
|
76
|
|
- }
|
|
|
82
|
+}
|