|
|
@@ -76,10 +76,17 @@ export default {
|
|
76
|
76
|
// TODO: Validate All routes hit by these methods using tokens in headers
|
|
77
|
77
|
// NOTE: This can be accomplished using sessionData.sessionToken,
|
|
78
|
78
|
// as it currently has the raw session token in it
|
|
79
|
|
- const userId = await this.grabUserIdByEmail(sessionData.email)
|
|
80
|
|
- currentProfileId = await this.grabProfileIdByUserId(userId)
|
|
|
79
|
+ const userId = await this.grabUserIdByEmail(
|
|
|
80
|
+ sessionData.email,
|
|
|
81
|
+ sessionData.sessionToken,
|
|
|
82
|
+ )
|
|
|
83
|
+ currentProfileId = await this.grabProfileIdByUserId(
|
|
|
84
|
+ userId,
|
|
|
85
|
+ sessionData.sessionToken,
|
|
|
86
|
+ )
|
|
81
|
87
|
this.responses = await this.grabResponsesByProfileId(
|
|
82
|
88
|
currentProfileId,
|
|
|
89
|
+ sessionData.sessionToken,
|
|
83
|
90
|
)
|
|
84
|
91
|
this.currentStep = this.responses.length + 3
|
|
85
|
92
|
this.goToStep(this.currentStep)
|
|
|
@@ -119,14 +126,17 @@ export default {
|
|
119
|
126
|
return validatedToken
|
|
120
|
127
|
}
|
|
121
|
128
|
},
|
|
122
|
|
- async grabUserIdByEmail(email) {
|
|
123
|
|
- const user = await fetchUserByEmail(email)
|
|
|
129
|
+ async grabUserIdByEmail(email, sessionToken) {
|
|
|
130
|
+ const user = await fetchUserByEmail(email, sessionToken)
|
|
124
|
131
|
if (!user) {
|
|
125
|
132
|
throw new Error('User NOT found by email')
|
|
126
|
133
|
} else return user.user_id
|
|
127
|
134
|
},
|
|
128
|
|
- async grabProfileIdByUserId(userId) {
|
|
129
|
|
- const profilesFromUserId = await fetchProfilesByUserId(userId)
|
|
|
135
|
+ async grabProfileIdByUserId(userId, sessionToken) {
|
|
|
136
|
+ const profilesFromUserId = await fetchProfilesByUserId(
|
|
|
137
|
+ userId,
|
|
|
138
|
+ sessionToken,
|
|
|
139
|
+ )
|
|
130
|
140
|
if (
|
|
131
|
141
|
profilesFromUserId.length === 1 &&
|
|
132
|
142
|
profilesFromUserId.status !== 401
|
|
|
@@ -139,17 +149,23 @@ export default {
|
|
139
|
149
|
throw new Error('No Profile for User ID found')
|
|
140
|
150
|
}
|
|
141
|
151
|
},
|
|
142
|
|
- async grabProfileByProfileId(profileId) {
|
|
143
|
|
- const profile = await fetchProfileByProfileId(profileId)
|
|
|
152
|
+ async grabProfileByProfileId(profileId, sessionToken) {
|
|
|
153
|
+ const profile = await fetchProfileByProfileId(
|
|
|
154
|
+ profileId,
|
|
|
155
|
+ sessionToken,
|
|
|
156
|
+ )
|
|
144
|
157
|
if (!profile || profile.status === 401) {
|
|
145
|
158
|
throw new Error(`No Profile Found for profileId ${profileId}`)
|
|
146
|
159
|
} else {
|
|
147
|
160
|
return profile
|
|
148
|
161
|
}
|
|
149
|
162
|
},
|
|
150
|
|
- async grabResponsesByProfileId(profileId) {
|
|
|
163
|
+ async grabResponsesByProfileId(profileId, sessionToken) {
|
|
151
|
164
|
const responses = []
|
|
152
|
|
- const profile = await this.grabProfileByProfileId(profileId)
|
|
|
165
|
+ const profile = await this.grabProfileByProfileId(
|
|
|
166
|
+ profileId,
|
|
|
167
|
+ sessionToken,
|
|
|
168
|
+ )
|
|
153
|
169
|
if (!profile.responses.length || profile.responses.status === 401) {
|
|
154
|
170
|
throw new Error(`No Responses Found for profileId ${profileId}`)
|
|
155
|
171
|
} else {
|