Procházet zdrojové kódy

:recycle: adding groupings and responses

neo
toj před 2 roky
rodič
revize
114bc7dd68

+ 42
- 0
backend/lib/models/grouping.js Zobrazit soubor

@@ -0,0 +1,42 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const groupingSchema = require('../schemas/groupings')
4
+const Profile = require('./profile')
5
+const Tag = require('./tag')
6
+
7
+module.exports = class Grouping extends Schwifty.Model {
8
+    static get tableName() {
9
+        return 'groupings'
10
+    }
11
+    static get relationMappings() {
12
+        return {
13
+            profiles: {
14
+                relation: Schwifty.Model.ManyToManyRelation,
15
+                modelClass: Profile,
16
+                join: {
17
+                    from: 'groupings.grouping_id',
18
+                    through: {
19
+                        from: 'memberships.grouping_id',
20
+                        to: 'memberships.profile_id',
21
+                    },
22
+                    to: 'profiles.profile_id',
23
+                },
24
+            },
25
+            tags: {
26
+                relation: Schwifty.Model.HasManyRelation,
27
+                modelClass: Tag,
28
+                join: {
29
+                    from: 'groupings.grouping_id',
30
+                    through: {
31
+                        from: 'tag_associations.grouping_id',
32
+                        to: 'tag_associations.tag_id',
33
+                    },
34
+                    to: 'tags.tag_id',
35
+                },
36
+            },
37
+        }
38
+    }
39
+    static get joiSchema() {
40
+        return groupingSchema.single
41
+    }
42
+}

+ 1
- 0
backend/lib/models/membership.js Zobrazit soubor

@@ -1,4 +1,5 @@
1 1
 const Schwifty = require('@hapipal/schwifty')
2
+
2 3
 const membershipSchema = require('../schemas/memberships')
3 4
 
4 5
 module.exports = class Membership extends Schwifty.Model {

+ 0
- 0
backend/lib/schemas/groupings.js Zobrazit soubor


+ 6
- 1
backend/lib/schemas/memberships.js Zobrazit soubor

@@ -1,7 +1,10 @@
1
+const Joi = require('joi')
2
+
1 3
 const validator = Joi.object({
2 4
     membership_id: Joi.number(),
3 5
     profile_id: Joi.number(),
4 6
     grouping_id: Joi.number(),
7
+    membership_type: Joi.string().required(),
5 8
 }).label('membership__single_validator')
6 9
 
7 10
 // single is used to define database models
@@ -9,7 +12,9 @@ const single = Joi.object({
9 12
     membership_id: Joi.number(),
10 13
     profile_id: Joi.number(),
11 14
     grouping_id: Joi.number(),
12
-    _is_deleted: Joi.number(),
15
+    membership_type: Joi.string().required(),
16
+    _can_edit: Joi.number().required(),
17
+    _is_active: Joi.number().required(),
13 18
 }).label('membership__single')
14 19
 
15 20
 module.exports = {

+ 17
- 0
backend/lib/schemas/response-keys.js Zobrazit soubor

@@ -0,0 +1,17 @@
1
+const singleResponseKey = Joi.object({
2
+    response_key_id: Joi.number().required(),
3
+    response_key_category: Joi.string().required(),
4
+    response_key_prompt: Joi.string().required(),
5
+    response_key_description: Joi.any(),
6
+    aspect: Joi.string().allow(null, ''),
7
+    category: Joi.string().allow(null, ''),
8
+    placeholder: Joi.string().allow(null, ''),
9
+    invalidInputPrompt: Joi.string().allow(null, ''),
10
+}).label('question_single')
11
+
12
+module.exports = {
13
+    single: singleResponse,
14
+    list: Joi.array().items(singleResponse).label('response_list'),
15
+    key: singleResponseKey,
16
+    keys: Joi.array().items(singleResponseKey).label('question_list'),
17
+}

+ 26
- 0
backend/lib/schemas/responses.js Zobrazit soubor

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

Načítá se…
Zrušit
Uložit