Sfoglia il codice sorgente

:gears: WIP finalSubmit function at end of onboarding

juan-filtering-match-pool
juancarbajal98 2 anni fa
parent
commit
9ed6f7c621
2 ha cambiato i file con 52 aggiunte e 1 eliminazioni
  1. 1
    1
      backend/lib/services/user.js
  2. 51
    0
      frontend/src/views/SurveyCompleteView.vue

+ 1
- 1
backend/lib/services/user.js Vedi File

@@ -328,7 +328,7 @@ module.exports = class UserService extends Schmervice.Service {
328 328
                     email: userCredentials.email,
329 329
                 },
330 330
             ],
331
-            templateId: 1,
331
+            templateId: 2,
332 332
             params: {
333 333
                 // TODO: Change this in production...
334 334
                 link: `localhost:3000/verify/${hashedAccessToken}`,

+ 51
- 0
frontend/src/views/SurveyCompleteView.vue Vedi File

@@ -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>

Loading…
Annulla
Salva