|
|
@@ -26,6 +26,12 @@ main.view--surveycomplete
|
|
26
|
26
|
</template>
|
|
27
|
27
|
|
|
28
|
28
|
<script>
|
|
|
29
|
+import {
|
|
|
30
|
+ createProfileForUserId,
|
|
|
31
|
+ currentProfile,
|
|
|
32
|
+ signUpUser
|
|
|
33
|
+} from '@/services'
|
|
|
34
|
+
|
|
29
|
35
|
export default {
|
|
30
|
36
|
props: {
|
|
31
|
37
|
answers: {
|
|
|
@@ -58,5 +64,50 @@ export default {
|
|
58
|
64
|
}
|
|
59
|
65
|
})
|
|
60
|
66
|
},
|
|
|
67
|
+ methods: {
|
|
|
68
|
+ changeAnswers(){
|
|
|
69
|
+ console.log('change answers')
|
|
|
70
|
+
|
|
|
71
|
+ },
|
|
|
72
|
+
|
|
|
73
|
+ async finalSubmit(){
|
|
|
74
|
+ // separate user info from responses
|
|
|
75
|
+ const [user, survey] = this._separateUserInfoFromResponses(this.answers)
|
|
|
76
|
+
|
|
|
77
|
+ // create user
|
|
|
78
|
+ const createdUser = await signUpUser(user)
|
|
|
79
|
+ if (!createdUser) return
|
|
|
80
|
+
|
|
|
81
|
+ // create profile
|
|
|
82
|
+ const userProfile = await createProfileForUserId(createdUser.user_id, survey)
|
|
|
83
|
+ if(!userProfile) return
|
|
|
84
|
+
|
|
|
85
|
+ /**
|
|
|
86
|
+ * Login only after there is a user and
|
|
|
87
|
+ * that user has a profile and all responses
|
|
|
88
|
+ */
|
|
|
89
|
+ this._setLoginForProfile(userProfile)
|
|
|
90
|
+
|
|
|
91
|
+ this.$router.push({ name: 'HomeView' })
|
|
|
92
|
+ },
|
|
|
93
|
+
|
|
|
94
|
+ // TODO write logic to parse answers
|
|
|
95
|
+ _separateUserInfoFromResponses(answers){
|
|
|
96
|
+ return ['','']
|
|
|
97
|
+ },
|
|
|
98
|
+
|
|
|
99
|
+ async _setLoginForProfile(profile){
|
|
|
100
|
+ const currentId = currentProfile.login(profile.profile_id)
|
|
|
101
|
+ if(currentId && profile.responses.length){
|
|
|
102
|
+ currentProfile.setResponses(profile.responses)
|
|
|
103
|
+ }
|
|
|
104
|
+ if (!currentProfile.isComplete) {
|
|
|
105
|
+ console.error(
|
|
|
106
|
+ `Profile ${currentProfile.id} is incomplete. Please make sure all survey questions have been answered.`,
|
|
|
107
|
+ )
|
|
|
108
|
+ return
|
|
|
109
|
+ }
|
|
|
110
|
+ }
|
|
|
111
|
+ }
|
|
61
|
112
|
}
|
|
62
|
113
|
</script>
|