Przeglądaj źródła

:sparkles: starting to consolidate joi schema definitions

tags/0.0.1
J 4 lat temu
rodzic
commit
45d84220c4

+ 2
- 6
backend/lib/models/grouping.js Wyświetl plik

@@ -1,15 +1,11 @@
1 1
 const Schwifty = require('@hapipal/schwifty')
2
-const Joi = require('joi')
2
+const groupingSchema = require('../schemas/groupings')
3 3
 
4 4
 module.exports = class Grouping extends Schwifty.Model {
5 5
     static get tableName() {
6 6
         return 'groupings'
7 7
     }
8 8
     static get joiSchema() {
9
-        return Joi.object({
10
-            grouping_id: Joi.number(),
11
-            grouping_name: Joi.string().required(),
12
-            grouping_type: Joi.string().required(),
13
-        })
9
+        return groupingSchema.single
14 10
     }
15 11
 }

+ 2
- 6
backend/lib/models/matchqueue.js Wyświetl plik

@@ -1,6 +1,7 @@
1 1
 const Schwifty = require('@hapipal/schwifty')
2 2
 const Joi = require('joi')
3 3
 const User = require('./user')
4
+const queueSchema = require('../schemas/queues')
4 5
 
5 6
 module.exports = class MatchQueue extends Schwifty.Model {
6 7
     static get tableName() {
@@ -23,11 +24,6 @@ module.exports = class MatchQueue extends Schwifty.Model {
23 24
         }
24 25
     }
25 26
     static get joiSchema() {
26
-        return Joi.object({
27
-            match_queue_id: Joi.number(),
28
-            profile_id: Joi.number().required(),
29
-            target_id: Joi.number().required(),
30
-            is_deleted: Joi.boolean().required(),
31
-        })
27
+        return queueSchema.single
32 28
     }
33 29
 }

+ 2
- 8
backend/lib/models/membership.js Wyświetl plik

@@ -1,18 +1,12 @@
1 1
 const Schwifty = require('@hapipal/schwifty')
2 2
 const Joi = require('joi')
3
+const membershipSchema = require('../schemas/memberships')
3 4
 
4 5
 module.exports = class Membership extends Schwifty.Model {
5 6
     static get tableName() {
6 7
         return 'memberships'
7 8
     }
8 9
     static get joiSchema() {
9
-        return Joi.object({
10
-            membership_id: Joi.number(),
11
-            profile_id: Joi.number().required(),
12
-            grouping_id: Joi.number().allow(null),
13
-            membership_type: Joi.string().required(),
14
-            can_edit: Joi.boolean().required(),
15
-            is_active: Joi.boolean().required(),
16
-        })
10
+        return membershipSchema.single
17 11
     }
18 12
 }

+ 2
- 3
backend/lib/models/response-key.js Wyświetl plik

@@ -1,13 +1,12 @@
1 1
 const Schwifty = require('@hapipal/schwifty')
2 2
 const Joi = require('joi')
3
+const surveyResponseSchema = require('../schemas/responses')
3 4
 
4 5
 module.exports = class ResponseKey extends Schwifty.Model {
5 6
     static get tableName() {
6 7
         return 'response_keys'
7 8
     }
8 9
     static get joiSchema() {
9
-        return Joi.object({
10
-            response_key_id: Joi.number().required(),
11
-        })
10
+        return surveyResponseSchema.key
12 11
     }
13 12
 }

+ 2
- 7
backend/lib/models/response.js Wyświetl plik

@@ -1,16 +1,11 @@
1 1
 const Schwifty = require('@hapipal/schwifty')
2
-const Joi = require('joi')
2
+const responseSchema = require('../schemas/responses')
3 3
 
4 4
 module.exports = class Response extends Schwifty.Model {
5 5
     static get tableName() {
6 6
         return 'responses'
7 7
     }
8 8
     static get joiSchema() {
9
-        return Joi.object({
10
-            response_id: Joi.number(),
11
-            profile_id: Joi.number(),
12
-            response_key_id: Joi.number(),
13
-            val: Joi.string(),
14
-        })
9
+        return responseSchema.single
15 10
     }
16 11
 }

+ 9
- 10
backend/lib/routes/membership/active.js Wyświetl plik

@@ -1,6 +1,9 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const apiSchema = require('../../schemas/api')
5
+const errorSchema = require('../../schemas/errors')
6
+const groupingSchema = require('../../schemas/groupings')
4 7
 
5 8
 const pluginConfig = {
6 9
     handlerType: 'grouping',
@@ -25,11 +28,9 @@ const validators = {
25 28
 }
26 29
 
27 30
 const responseSchemas = {
28
-    groupingsList: Joi.object({
29
-        grouping_id: Joi.number(),
30
-        grouping_name: Joi.string(),
31
-        grouping_type: Joi.string(),
32
-    }),
31
+    single: groupingSchema.single,
32
+    list: groupingSchema.list,
33
+    error: errorSchema.single
33 34
 }
34 35
 
35 36
 module.exports = {
@@ -73,11 +74,9 @@ module.exports = {
73 74
 
74 75
         /** Validate the server response */
75 76
         response: {
76
-            schema: Joi.object({
77
-                ok: Joi.bool(),
78
-                handler: Joi.string(),
79
-                data: Joi.array().items(responseSchemas.groupingsList),
80
-            }),
77
+            schema: apiSchema.single.append({
78
+                data: responseSchemas.list
79
+            })
81 80
         },
82 81
     },
83 82
 }

+ 9
- 14
backend/lib/routes/membership/join.js Wyświetl plik

@@ -1,5 +1,9 @@
1 1
 const Joi = require('joi')
2 2
 
3
+const apiSchema = require('../../schemas/api')
4
+const errorSchema = require('../../schemas/errors')
5
+const groupingSchema = require('../../schemas/groupings')
6
+
3 7
 const pluginConfig = {
4 8
     handlerType: 'grouping',
5 9
     docs: {
@@ -10,13 +14,10 @@ const pluginConfig = {
10 14
 
11 15
 const validators = {
12 16
     params: Joi.object({ profile_id: Joi.number() }),
13
-    payload: Joi.object({
17
+    payload: groupingSchema.single.append({
14 18
         target_id: Joi.number().required(),
15
-        grouping_id: Joi.number().allow(null),
16
-        grouping_name: Joi.string().allow(null),
17
-        grouping_type: Joi.string().allow(null),
18 19
         role: Joi.string(),
19
-    }),
20
+    })
20 21
 }
21 22
 
22 23
 const responseSchemas = {
@@ -24,9 +25,7 @@ const responseSchemas = {
24 25
         memberships: Joi.array().items(),
25 26
         hasMatch: Joi.boolean()
26 27
     }),
27
-    error: Joi.object({
28
-        error: Joi.string(),
29
-    }),
28
+    error: errorSchema.single
30 29
 }
31 30
 
32 31
 module.exports = {
@@ -104,14 +103,10 @@ module.exports = {
104 103
         /** Validate the server response */
105 104
         response: {
106 105
             status: {
107
-                200: Joi.object({
108
-                    ok: Joi.bool(),
109
-                    handler: Joi.string(),
106
+                200: apiSchema.single.append({
110 107
                     data: responseSchemas.response,
111 108
                 }),
112
-                409: Joi.object({
113
-                    ok: Joi.bool(),
114
-                    handler: Joi.string(),
109
+                409: apiSchema.single.append({
115 110
                     data: responseSchemas.error,
116 111
                 }),
117 112
             },

+ 2
- 4
backend/lib/routes/membership/leave.js Wyświetl plik

@@ -1,7 +1,7 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
-
4
+const apiSchema = require('../../schemas/api')
5 5
 const pluginConfig = {
6 6
     handlerType: 'grouping',
7 7
     docs: {
@@ -40,9 +40,7 @@ module.exports = {
40 40
         },
41 41
         validate: validators.leave,
42 42
         response: {
43
-            schema: Joi.object({
44
-                ok: Joi.bool(),
45
-                handler: Joi.string(),
43
+            schema: apiSchema.single.append({
46 44
                 data: validators.leave,
47 45
             }),
48 46
             failAction: 'log',

+ 6
- 10
backend/lib/routes/profile/match.js Wyświetl plik

@@ -1,6 +1,8 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const apiSchema = require('../../schemas/api')
5
+const errorSchema = require('../../schemas/errors')
4 6
 
5 7
 const pluginConfig = {
6 8
     handlerType: 'match',
@@ -14,9 +16,7 @@ const validators = {}
14 16
 
15 17
 const responseSchemas = {
16 18
     response: Joi.array().items(Joi.object()),
17
-    error: Joi.object({
18
-        error: Joi.string(),
19
-    }),
19
+    error: errorSchema.single
20 20
 }
21 21
 
22 22
 module.exports = {
@@ -65,16 +65,12 @@ module.exports = {
65 65
         /** Validate the server response */
66 66
         response: {
67 67
             status: {
68
-                200: Joi.object({
69
-                    ok: Joi.bool(),
70
-                    handler: Joi.string(),
68
+                200: apiSchema.single.append({
71 69
                     data: responseSchemas.response,
72 70
                 }),
73
-                409: Joi.object({
74
-                    ok: Joi.bool(),
75
-                    handler: Joi.string(),
71
+                409: apiSchema.single.append({
76 72
                     data: responseSchemas.error,
77
-                }),
73
+                })
78 74
             },
79 75
         },
80 76
     },

+ 9
- 12
backend/lib/routes/profile/patch-queue.js Wyświetl plik

@@ -2,6 +2,9 @@
2 2
 
3 3
 const Joi = require('joi')
4 4
 
5
+const apiSchema = require('../../schemas/api')
6
+const errorSchema = require('../../schemas/errors')
7
+
5 8
 const pluginConfig = {
6 9
     handlerType: 'profile',
7 10
     docs: {
@@ -11,7 +14,7 @@ const pluginConfig = {
11 14
 }
12 15
 
13 16
 const responseSchemas = {
14
-    responses: Joi.array().items(
17
+    response: Joi.array().items(
15 18
         Joi.alternatives().try(
16 19
             Joi.number(),
17 20
             Joi.object({
@@ -26,9 +29,7 @@ const responseSchemas = {
26 29
             }),
27 30
         ),
28 31
     ),
29
-    error: Joi.object({
30
-        error: Joi.string(),
31
-    }),
32
+    error: errorSchema.single
32 33
 }
33 34
 
34 35
 const validators = {
@@ -86,16 +87,12 @@ module.exports = {
86 87
         /** Validate the server response */
87 88
         response: {
88 89
             status: {
89
-                200: Joi.object({
90
-                    ok: Joi.bool(),
91
-                    handler: Joi.string(),
92
-                    data: responseSchemas.responses,
90
+                200: apiSchema.single.append({
91
+                    data: responseSchemas.response,
93 92
                 }),
94
-                409: Joi.object({
95
-                    ok: Joi.bool(),
96
-                    handler: Joi.string(),
93
+                409: apiSchema.single.append({
97 94
                     data: responseSchemas.error,
98
-                }),
95
+                })
99 96
             },
100 97
         },
101 98
     },

+ 8
- 12
backend/lib/routes/profile/queue.js Wyświetl plik

@@ -1,6 +1,8 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const apiSchema = require('../../schemas/api')
5
+const errorSchema = require('../../schemas/errors')
4 6
 
5 7
 const pluginConfig = {
6 8
     handlerType: 'profile',
@@ -11,7 +13,7 @@ const pluginConfig = {
11 13
 }
12 14
 
13 15
 const responseSchemas = {
14
-    responses: Joi.array().items(
16
+    response: Joi.array().items(
15 17
         Joi.alternatives().try(
16 18
             Joi.number(),
17 19
             Joi.object({
@@ -25,9 +27,7 @@ const responseSchemas = {
25 27
             }),
26 28
         )
27 29
     ),
28
-    error: Joi.object({
29
-        error: Joi.string(),
30
-    }),
30
+    error: errorSchema.single
31 31
 }
32 32
 
33 33
 const validators = {
@@ -82,16 +82,12 @@ module.exports = {
82 82
         /** Validate the server response */
83 83
         response: {
84 84
             status: {
85
-                200: Joi.object({
86
-                    ok: Joi.bool(),
87
-                    handler: Joi.string(),
88
-                    data: responseSchemas.responses,
85
+                200: apiSchema.single.append({
86
+                    data: responseSchemas.response,
89 87
                 }),
90
-                409: Joi.object({
91
-                    ok: Joi.bool(),
92
-                    handler: Joi.string(),
88
+                409: apiSchema.single.append({
93 89
                     data: responseSchemas.error,
94
-                }),
90
+                })
95 91
             },
96 92
         },
97 93
     },

+ 9
- 19
backend/lib/routes/profile/respond.js Wyświetl plik

@@ -1,6 +1,9 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const apiSchema = require('../../schemas/api')
5
+const errorSchema = require('../../schemas/errors')
6
+const surveyResponseSchema = require('../../schemas/responses')
4 7
 
5 8
 const pluginConfig = {
6 9
     handlerType: 'profile',
@@ -11,17 +14,8 @@ const pluginConfig = {
11 14
 }
12 15
 
13 16
 const responseSchemas = {
14
-    responses: Joi.array().items(
15
-        Joi.object({
16
-            response_id: Joi.number().required(),
17
-            profile_id: Joi.number().required(),
18
-            response_key_id: Joi.number().required(),
19
-            val: Joi.string().required(),
20
-        }),
21
-    ),
22
-    error: Joi.object({
23
-        error: Joi.string(),
24
-    }),
17
+    response: surveyResponseSchema.list,
18
+    error: errorSchema.single
25 19
 }
26 20
 
27 21
 const validators = {
@@ -98,16 +92,12 @@ module.exports = {
98 92
         /** Validate the server response */
99 93
         response: {
100 94
             status: {
101
-                201: Joi.object({
102
-                    ok: Joi.bool(),
103
-                    handler: Joi.string(),
104
-                    data: responseSchemas.responses,
95
+                201: apiSchema.single.append({
96
+                    data: responseSchemas.response,
105 97
                 }),
106
-                409: Joi.object({
107
-                    ok: Joi.bool(),
108
-                    handler: Joi.string(),
98
+                409: apiSchema.single.append({
109 99
                     data: responseSchemas.error,
110
-                }),
100
+                })
111 101
             },
112 102
         },
113 103
     },

+ 6
- 10
backend/lib/routes/profile/score.js Wyświetl plik

@@ -1,6 +1,8 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const apiSchema = require('../../schemas/api')
5
+const errorSchema = require('../../schemas/errors')
4 6
 
5 7
 const pluginConfig = {
6 8
     handlerType: 'score',
@@ -30,9 +32,7 @@ const validators = {
30 32
 
31 33
 const responseSchemas = {
32 34
     response: Joi.array().items(),
33
-    error: Joi.object({
34
-        error: Joi.string(),
35
-    }),
35
+    error: errorSchema.single
36 36
 }
37 37
 
38 38
 module.exports = {
@@ -95,16 +95,12 @@ module.exports = {
95 95
         /** Validate the server response */
96 96
         response: {
97 97
             status: {
98
-                200: Joi.object({
99
-                    ok: Joi.bool(),
100
-                    handler: Joi.string(),
98
+                200: apiSchema.single.append({
101 99
                     data: responseSchemas.response,
102 100
                 }),
103
-                409: Joi.object({
104
-                    ok: Joi.bool(),
105
-                    handler: Joi.string(),
101
+                409: apiSchema.single.append({
106 102
                     data: responseSchemas.error,
107
-                }),
103
+                })
108 104
             },
109 105
         },
110 106
     },

+ 9
- 19
backend/lib/routes/profile/update.js Wyświetl plik

@@ -1,6 +1,9 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const apiSchema = require('../../schemas/api')
5
+const errorSchema = require('../../schemas/errors')
6
+const surveyResponseSchema = require('../../schemas/responses')
4 7
 
5 8
 const pluginConfig = {
6 9
     handlerType: 'profile',
@@ -11,17 +14,8 @@ const pluginConfig = {
11 14
 }
12 15
 
13 16
 const responseSchemas = {
14
-    responses: Joi.array().items(
15
-        Joi.object({
16
-            response_id: Joi.number().required(),
17
-            profile_id: Joi.number().required(),
18
-            response_key_id: Joi.number().required(),
19
-            val: Joi.string().required(),
20
-        }),
21
-    ),
22
-    error: Joi.object({
23
-        error: Joi.string(),
24
-    }),
17
+    response: surveyResponseSchema.list,
18
+    error: errorSchema.single
25 19
 }
26 20
 
27 21
 const validators = {
@@ -89,16 +83,12 @@ module.exports = {
89 83
         /** Validate the server response */
90 84
         response: {
91 85
             status: {
92
-                200: Joi.object({
93
-                    ok: Joi.bool(),
94
-                    handler: Joi.string(),
95
-                    data: responseSchemas.responses,
86
+                200: apiSchema.single.append({
87
+                    data: responseSchemas.response,
96 88
                 }),
97
-                409: Joi.object({
98
-                    ok: Joi.bool(),
99
-                    handler: Joi.string(),
89
+                409: apiSchema.single.append({
100 90
                     data: responseSchemas.error,
101
-                }),
91
+                })
102 92
             },
103 93
         },
104 94
     },

+ 5
- 10
backend/lib/routes/survey/questions.js Wyświetl plik

@@ -1,6 +1,8 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const apiSchema = require('../../schemas/api')
5
+const surveyResponseSchema = require('../../schemas/responses')
4 6
 
5 7
 const pluginConfig = {
6 8
     handlerType: 'survey',
@@ -22,12 +24,7 @@ const validators = {
22 24
     // payload: true,
23 25
 }
24 26
 const responseSchemas = {
25
-    responseKeysList: Joi.object({
26
-        response_key_id: Joi.number().required(),
27
-        response_key_category: Joi.string().required(),
28
-        response_key_prompt: Joi.string().required(),
29
-        response_key_description: Joi.any(),
30
-    }),
27
+    response: surveyResponseSchema.keys,
31 28
 }
32 29
 
33 30
 module.exports = {
@@ -62,10 +59,8 @@ module.exports = {
62 59
 
63 60
         /** Validate the server response */
64 61
         response: {
65
-            schema: Joi.object({
66
-                ok: Joi.bool(),
67
-                handler: Joi.string(),
68
-                data: Joi.array().items(responseSchemas.responseKeysList),
62
+            schema: apiSchema.single.append({
63
+                data: responseSchemas.response
69 64
             }),
70 65
             failAction: 'log',
71 66
         },

+ 5
- 7
backend/lib/routes/survey/responses.js Wyświetl plik

@@ -1,6 +1,8 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const apiSchema = require('../../schemas/api')
5
+const surveyResponseSchema = require('../../schemas/responses')
4 6
 
5 7
 const pluginConfig = {
6 8
     handlerType: 'survey',
@@ -22,9 +24,7 @@ const validators = {
22 24
     // payload: true,
23 25
 }
24 26
 const responseSchemas = {
25
-    responseKeysList: Joi.object({
26
-        response_key_id: Joi.number().required(),
27
-    }),
27
+    response: surveyResponseSchema.keys
28 28
 }
29 29
 
30 30
 module.exports = {
@@ -59,10 +59,8 @@ module.exports = {
59 59
 
60 60
         /** Validate the server response */
61 61
         response: {
62
-            schema: Joi.object({
63
-                ok: Joi.bool(),
64
-                handler: Joi.string(),
65
-                data: Joi.array().items(responseSchemas.responseKeysList),
62
+            schema: apiSchema.single.append({
63
+                data: responseSchemas.response
66 64
             }),
67 65
             failAction: 'log',
68 66
         },

+ 2
- 3
backend/lib/routes/user/create-profile.js Wyświetl plik

@@ -1,6 +1,7 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const errorSchema = require('../../schemas/errors')
4 5
 
5 6
 const pluginConfig = {
6 7
     handlerType: 'user',
@@ -39,9 +40,7 @@ const responseSchemas = {
39 40
         // and this route utilizes getCompleteProfiles
40 41
         user_name: Joi.string(),
41 42
     }),
42
-    error: Joi.object({
43
-        error: Joi.string(),
44
-    }),
43
+    error: errorSchema.single
45 44
 }
46 45
 
47 46
 module.exports = {

+ 2
- 3
backend/lib/routes/user/list-profiles.js Wyświetl plik

@@ -1,6 +1,7 @@
1 1
 'use strict'
2 2
 
3 3
 const Joi = require('joi')
4
+const errorSchema = require('../../schemas/errors')
4 5
 
5 6
 const pluginConfig = {
6 7
     handlerType: 'user',
@@ -46,9 +47,7 @@ const responseSchemas = {
46 47
         ),
47 48
         user_type: Joi.string().required(),
48 49
     }),
49
-    error: Joi.object({
50
-        error: Joi.string(),
51
-    }),
50
+    error: errorSchema.single
52 51
 }
53 52
 
54 53
 module.exports = {

+ 12
- 0
backend/lib/schemas/api.js Wyświetl plik

@@ -0,0 +1,12 @@
1
+'use strict'
2
+
3
+const Joi = require('joi')
4
+
5
+const singleApiResponse = Joi.object({
6
+    ok: Joi.bool(),
7
+    handler: Joi.string(),
8
+}).label('api_single')
9
+
10
+module.exports = {
11
+    single: singleApiResponse
12
+}

+ 11
- 0
backend/lib/schemas/errors.js Wyświetl plik

@@ -0,0 +1,11 @@
1
+'use strict'
2
+
3
+const Joi = require('joi')
4
+
5
+const singleError = Joi.object({
6
+    error: Joi.string(),
7
+}).label('error_single')
8
+
9
+module.exports = {
10
+    single: singleError
11
+}

+ 14
- 0
backend/lib/schemas/groupings.js Wyświetl plik

@@ -0,0 +1,14 @@
1
+'use strict'
2
+
3
+const Joi = require('joi')
4
+
5
+const singleGrouping = Joi.object({
6
+    grouping_id: Joi.number(),
7
+    grouping_name: Joi.string(),
8
+    grouping_type: Joi.string(),
9
+}).label('grouping_single')
10
+
11
+module.exports = {
12
+    single: singleGrouping,
13
+    list: Joi.array().items(singleGrouping).label('grouping_list')
14
+}

+ 17
- 0
backend/lib/schemas/memberships.js Wyświetl plik

@@ -0,0 +1,17 @@
1
+'use strict'
2
+
3
+const Joi = require('joi')
4
+
5
+const singleMembership = Joi.object({
6
+    membership_id: Joi.number(),
7
+    profile_id: Joi.number().required(),
8
+    grouping_id: Joi.number().allow(null),
9
+    membership_type: Joi.string().required(),
10
+    can_edit: Joi.boolean().required(),
11
+    is_active: Joi.boolean().required(),
12
+}).label('membership_single')
13
+
14
+module.exports = {
15
+    single: singleMembership,
16
+    list: Joi.array().items(singleMembership).label('membership_list')
17
+}

+ 15
- 0
backend/lib/schemas/queues.js Wyświetl plik

@@ -0,0 +1,15 @@
1
+'use strict'
2
+
3
+const Joi = require('joi')
4
+
5
+const singleQueueEntry = Joi.object({
6
+    match_queue_id: Joi.number(),
7
+    profile_id: Joi.number().required(),
8
+    target_id: Joi.number().required(),
9
+    is_deleted: Joi.boolean().required(),
10
+}).label('queue_single')
11
+
12
+module.exports = {
13
+    single: singleQueueEntry,
14
+    list: Joi.array().items(singleQueueEntry).label('queue_list')
15
+}

+ 24
- 0
backend/lib/schemas/responses.js Wyświetl plik

@@ -0,0 +1,24 @@
1
+'use strict'
2
+
3
+const Joi = require('joi')
4
+
5
+const singleResponse = Joi.object({
6
+    response_key_id: Joi.number(),
7
+    response_id: Joi.number(),
8
+    profile_id: Joi.number(),
9
+    val: Joi.string(),
10
+}).label('response_single')
11
+
12
+const singleResponseKey = Joi.object({
13
+    response_key_id: Joi.number().required(),
14
+    response_key_category: Joi.string().required(),
15
+    response_key_prompt: Joi.string().required(),
16
+    response_key_description: Joi.any(),
17
+}).label('question_single')
18
+
19
+module.exports = {
20
+    single: singleResponse,
21
+    list: Joi.array().items(singleResponse).label('response_list'),
22
+    key: singleResponseKey,
23
+    keys: Joi.array().items(singleResponseKey).label('question_list')
24
+}

+ 13
- 8277
backend/package-lock.json
Plik diff jest za duży
Wyświetl plik


+ 7
- 3
backend/tests/score.spec.js Wyświetl plik

@@ -9,6 +9,10 @@ const plugin = require('../lib/plugins/profile')
9 9
 const Profile = require('../lib/models/profile')
10 10
 const ZipCode = require('../lib/models/zip-code')
11 11
 const MatchQueue = require('../lib/models/matchqueue')
12
+
13
+// !: Must match the key set in servives/profile.js
14
+const zipcodeKey = 7 
15
+
12 16
 /**
13 17
  * Route parameters
14 18
  */
@@ -24,7 +28,7 @@ const mockReturn = {
24 28
             responses: [
25 29
                 { val: '120' },
26 30
                 { val: '200' },
27
-                { response_key_id: 16, val: '90065' },
31
+                { response_key_id: zipcodeKey, val: '90065' },
28 32
             ],
29 33
         },
30 34
         {
@@ -33,7 +37,7 @@ const mockReturn = {
33 37
             responses: [
34 38
                 { val: '120' },
35 39
                 { val: '200' },
36
-                { response_key_id: 16, val: '96741' },
40
+                { response_key_id: zipcodeKey, val: '96741' },
37 41
             ],
38 42
         },
39 43
         {
@@ -42,7 +46,7 @@ const mockReturn = {
42 46
             responses: [
43 47
                 { val: '180' },
44 48
                 { val: '140' },
45
-                { response_key_id: 16, val: '97002' },
49
+                { response_key_id: zipcodeKey, val: '97002' },
46 50
             ],
47 51
         },
48 52
     ],

Ładowanie…
Anuluj
Zapisz