Przeglądaj źródła

:construction: Started validation for survey procedures

tabs-content
tomit4 3 lat temu
rodzic
commit
3a32ac2c02

+ 1
- 5
frontend/src/components/onboarding/FormInput.vue Wyświetl plik

23
     }),
23
     }),
24
     methods: {
24
     methods: {
25
         handleSubmit(answerInfo) {
25
         handleSubmit(answerInfo) {
26
-            if (answerInfo.question.survey_stage === 'password') {
27
-                this.$emit('update-answers') // don't reveal password here...
28
-            } else {
29
-                this.$emit('update-answers', answerInfo)
30
-            }
26
+            this.$emit('update-answers', answerInfo)
31
         },
27
         },
32
         submitImage() {
28
         submitImage() {
33
             let payload = {
29
             let payload = {

+ 9
- 2
frontend/src/components/onboarding/QuestionResponse.vue Wyświetl plik

26
             { answer: 4 },
26
             { answer: 4 },
27
             { answer: 5 },
27
             { answer: 5 },
28
         ],
28
         ],
29
+        isAnswered: false
29
     }),
30
     }),
30
     methods: {
31
     methods: {
31
         onUpdate(e) {
32
         onUpdate(e) {
33
+            this.isAnswered = true
32
             this.$emit('updated', { ...this.question, answer: e + 1 })
34
             this.$emit('updated', { ...this.question, answer: e + 1 })
33
         },
35
         },
36
+        // TODO: render message to user on why they cannot proceed
34
         updateAnswers() {
37
         updateAnswers() {
35
-            this.$emit('update-is-answered', this.question.id)
38
+            this.isAnswered ?
39
+            this.$emit('update-is-answered', this.question.id) :
40
+            console.error('no selection made')
36
         },
41
         },
37
         updateAll() {
42
         updateAll() {
38
-            this.$emit('update-all')
43
+            this.isAnswered ? 
44
+            this.$emit('update-all') : 
45
+            console.error('no selection made')
39
         }
46
         }
40
     },
47
     },
41
 }
48
 }

+ 31
- 0
frontend/src/entities/survey/survey.answer.schema.js Wyświetl plik

1
+import Joi from 'joi'
2
+
3
+/**
4
+ * answers schema object
5
+ */
6
+const answersSchema = {
7
+    type: 'object',
8
+    properties: Joi.object().keys({
9
+        name: Joi.string().required(),
10
+        email: Joi.string().email({ minDomainSegments: 2, tlds: false }),
11
+        // TODO: Refine password regex to have more secure requirements
12
+        password: Joi.string().min(10).max(30).pattern(new RegExp('[a-zA-Z0-9]+')),
13
+        // TODO: Change if going international (only works in usa)
14
+        zipcode: Joi.string().min(5).max(5).pattern(new RegExp('^[0-9]{5}$')),
15
+        seeking: Joi.string(),
16
+        urgency: Joi.string(),
17
+        presence: Joi.string(),
18
+        duration: Joi.string(),
19
+        pronouns: Joi.string(),
20
+        language: Joi.string(),
21
+        image: Joi.any(),
22
+        distance: Joi.string(),
23
+        blurb: Joi.string(),
24
+        aspects: Joi.array().items(Joi.number().allow(null))
25
+    }),
26
+    validate(instance) {
27
+        return this.properties.validate(instance)
28
+    },
29
+}
30
+
31
+export { answersSchema }

+ 9
- 0
frontend/src/entities/survey/survey.js Wyświetl plik

1
 /** @module survey/survey */
1
 /** @module survey/survey */
2
 import { _baseRecord } from '../index.js'
2
 import { _baseRecord } from '../index.js'
3
 import { surveySchema } from './survey.schema.js'
3
 import { surveySchema } from './survey.schema.js'
4
+import { answersSchema } from './survey.answer.schema.js'
4
 
5
 
5
 const SCORED = [1, 2, 3, 4, 5, 6]
6
 const SCORED = [1, 2, 3, 4, 5, 6]
6
 const _isScored = id => SCORED.includes(id)
7
 const _isScored = id => SCORED.includes(id)
38
         console.log('this.aspectQuestions: ', JSON.stringify(this.aspectQuestions))
39
         console.log('this.aspectQuestions: ', JSON.stringify(this.aspectQuestions))
39
     }
40
     }
40
 
41
 
42
+    validateAnswer(answer) {
43
+        const validate = answersSchema.validate(answer)
44
+        if (validate.error) {
45
+            console.error(`error: ${validate.error}`)
46
+        }
47
+        return !validate.error ? true: false
48
+    }
49
+
41
     isValid() {
50
     isValid() {
42
         const validate = surveySchema.validate(this)
51
         const validate = surveySchema.validate(this)
43
 
52
 

+ 8
- 1
frontend/src/views/OnboardingView.vue Wyświetl plik

61
         },
61
         },
62
         updateAnswers(payload) {
62
         updateAnswers(payload) {
63
             // null payload is passed on splash page
63
             // null payload is passed on splash page
64
-            if (payload) {
64
+            if (this.currentStep !== 0) {
65
+                console.log('this.survey >>', this.survey)
65
                 const k = payload.question.survey_stage
66
                 const k = payload.question.survey_stage
66
                 this.answered[k] = payload.input
67
                 this.answered[k] = payload.input
68
+                // TODO: render message to user on why they cannot proceed
69
+                if (!this.survey.validateAnswer(this.answered)) {
70
+                    return console.error('invalid answer')
71
+                }
72
+                // once validated, don't log password in answered object
73
+                this.answered[k] = k === 'password' ? undefined : payload.input 
67
                 console.log(`Updated answers: ${JSON.stringify(this.answered)}`)
74
                 console.log(`Updated answers: ${JSON.stringify(this.answered)}`)
68
                 if (k === 'aspects') return
75
                 if (k === 'aspects') return
69
             }
76
             }

Ładowanie…
Anuluj
Zapisz