|
|
@@ -35,11 +35,6 @@ main.view--onboarding
|
|
35
|
35
|
|
|
36
|
36
|
<script>
|
|
37
|
37
|
import { Authenticator } from '../services/auth.service.js'
|
|
38
|
|
-import { fetchUserByEmail } from '../services/user.service.js'
|
|
39
|
|
-import {
|
|
40
|
|
- fetchProfilesByUserId,
|
|
41
|
|
- fetchProfileByProfileId,
|
|
42
|
|
-} from '../services/profile.service.js'
|
|
43
|
38
|
import { surveyFactory } from '@/utils'
|
|
44
|
39
|
import stepViews from '@/components/onboarding'
|
|
45
|
40
|
import SurveyCompleteView from './SurveyCompleteView.vue'
|
|
|
@@ -67,21 +62,8 @@ export default {
|
|
67
|
62
|
hashedAccessToken = this.grabStoredCookie('siimee_access')
|
|
68
|
63
|
try {
|
|
69
|
64
|
const sessionData = await this.verifySession(hashedAccessToken)
|
|
70
|
|
- console.log('sessionData :=>', sessionData)
|
|
71
|
|
- // TODO: Move this logic onto the backend and have it
|
|
72
|
|
- // returned in verifySession(hashedSessionToken)
|
|
73
|
|
- const userId = await this.grabUserIdByEmail(
|
|
74
|
|
- sessionData.email,
|
|
75
|
|
- sessionData.accessToken,
|
|
76
|
|
- )
|
|
77
|
|
- currentProfileId = await this.grabProfileIdByUserId(
|
|
78
|
|
- userId,
|
|
79
|
|
- sessionData.accessToken,
|
|
80
|
|
- )
|
|
81
|
|
- this.responses = await this.grabResponsesByProfileId(
|
|
82
|
|
- currentProfileId,
|
|
83
|
|
- sessionData.accessToken,
|
|
84
|
|
- )
|
|
|
65
|
+ currentProfileId = sessionData.profileId
|
|
|
66
|
+ this.responses = sessionData.responses
|
|
85
|
67
|
this.currentStep = this.responses.length + 3
|
|
86
|
68
|
this.goToStep(this.currentStep)
|
|
87
|
69
|
} catch (err) {
|
|
|
@@ -108,11 +90,9 @@ export default {
|
|
108
|
90
|
cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
|
|
109
|
91
|
return cookieVal
|
|
110
|
92
|
},
|
|
111
|
|
- // TODO: sessionToken is flying around far too often,
|
|
112
|
|
- // see above TODO regarding moving most of this logic to the backend
|
|
113
|
93
|
async verifySession(hashedAccessToken) {
|
|
114
|
94
|
if (!hashedAccessToken)
|
|
115
|
|
- return console.warn('WARNING :=> sessionToken is not defined')
|
|
|
95
|
+ return console.warn('WARNING :=> accessToken is not defined')
|
|
116
|
96
|
const validatedToken = await this.authenticator.validateSession(
|
|
117
|
97
|
hashedAccessToken,
|
|
118
|
98
|
)
|
|
|
@@ -122,58 +102,6 @@ export default {
|
|
122
|
102
|
return validatedToken
|
|
123
|
103
|
}
|
|
124
|
104
|
},
|
|
125
|
|
- async grabUserIdByEmail(email, accessToken) {
|
|
126
|
|
- const user = await fetchUserByEmail(email, accessToken)
|
|
127
|
|
- if (!user) {
|
|
128
|
|
- throw new Error('User NOT found by email')
|
|
129
|
|
- } else return user.user_id
|
|
130
|
|
- },
|
|
131
|
|
- async grabProfileIdByUserId(userId, accessToken) {
|
|
132
|
|
- const profilesFromUserId = await fetchProfilesByUserId(
|
|
133
|
|
- userId,
|
|
134
|
|
- accessToken,
|
|
135
|
|
- )
|
|
136
|
|
- if (
|
|
137
|
|
- profilesFromUserId.length === 1 &&
|
|
138
|
|
- profilesFromUserId.status !== 401
|
|
139
|
|
- ) {
|
|
140
|
|
- return profilesFromUserId[0].profile_id
|
|
141
|
|
- } else if (profilesFromUserId.length > 1) {
|
|
142
|
|
- // TODO: Refactor once more is known on users with multiple profiles
|
|
143
|
|
- throw new Error('Multiple Profiles for this User ID')
|
|
144
|
|
- } else {
|
|
145
|
|
- throw new Error('No Profile for User ID found')
|
|
146
|
|
- }
|
|
147
|
|
- },
|
|
148
|
|
- async grabProfileByProfileId(profileId, accessToken) {
|
|
149
|
|
- const profile = await fetchProfileByProfileId(
|
|
150
|
|
- profileId,
|
|
151
|
|
- accessToken,
|
|
152
|
|
- )
|
|
153
|
|
- if (!profile || profile.status === 401) {
|
|
154
|
|
- throw new Error(`No Profile Found for profileId ${profileId}`)
|
|
155
|
|
- } else {
|
|
156
|
|
- return profile
|
|
157
|
|
- }
|
|
158
|
|
- },
|
|
159
|
|
- async grabResponsesByProfileId(profileId, accessToken) {
|
|
160
|
|
- const responses = []
|
|
161
|
|
- const profile = await this.grabProfileByProfileId(
|
|
162
|
|
- profileId,
|
|
163
|
|
- accessToken,
|
|
164
|
|
- )
|
|
165
|
|
- if (!profile.responses.length || profile.responses.status === 401) {
|
|
166
|
|
- throw new Error(`No Responses Found for profileId ${profileId}`)
|
|
167
|
|
- } else {
|
|
168
|
|
- profile.responses.forEach(response => {
|
|
169
|
|
- responses.push({
|
|
170
|
|
- response_key_id: response.response_key_id,
|
|
171
|
|
- val: response.val,
|
|
172
|
|
- })
|
|
173
|
|
- })
|
|
174
|
|
- return responses
|
|
175
|
|
- }
|
|
176
|
|
- },
|
|
177
|
105
|
async updateAnswers(payload) {
|
|
178
|
106
|
if (payload) {
|
|
179
|
107
|
const k = payload.question.survey_stage
|
|
|
@@ -192,7 +120,7 @@ export default {
|
|
192
|
120
|
this.responses.push(response)
|
|
193
|
121
|
if (k === 'aspects') return
|
|
194
|
122
|
}
|
|
195
|
|
- // If user has finished minimum profile creation,
|
|
|
123
|
+ // NOTE: If user has finished minimum profile creation,
|
|
196
|
124
|
// Adds survey answers to responses table and verifies tokens on each step
|
|
197
|
125
|
if (currentProfileId) {
|
|
198
|
126
|
await surveyFactory.addNewSurveyAnswer(
|