Procházet zdrojové kódy

:recycle: adding membership models

neo
toj před 2 roky
rodič
revize
f7a39946a8

+ 11
- 0
backend/lib/models/memberships.js Zobrazit soubor

@@ -0,0 +1,11 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+const membershipSchema = require('../schemas/memberships')
3
+
4
+module.exports = class Membership extends Schwifty.Model {
5
+    static get tableName() {
6
+        return 'memberships'
7
+    }
8
+    static get joiSchema() {
9
+        return membershipSchema.single
10
+    }
11
+}

+ 45
- 0
backend/lib/models/profile.js Zobrazit soubor

@@ -0,0 +1,45 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+const Joi = require('joi')
3
+const TagAssociation = require('./tag-association')
4
+const Response = require('./response')
5
+const User = require('./user')
6
+
7
+module.exports = class Profile extends Schwifty.Model {
8
+    static get tableName() {
9
+        return 'profiles'
10
+    }
11
+    static get relationMappings() {
12
+        return {
13
+            tags: {
14
+                relation: Schwifty.Model.HasManyRelation,
15
+                modelClass: TagAssociation,
16
+                join: {
17
+                    from: 'tag_associations.profile_id',
18
+                    to: 'profiles.profile_id',
19
+                },
20
+            },
21
+            responses: {
22
+                relation: Schwifty.Model.HasManyRelation,
23
+                modelClass: Response,
24
+                join: {
25
+                    from: 'responses.profile_id',
26
+                    to: 'profiles.profile_id',
27
+                },
28
+            },
29
+            user: {
30
+                relation: Schwifty.Model.BelongsToOneRelation,
31
+                modelClass: User,
32
+                join: {
33
+                    from: 'users.user_id',
34
+                    to: 'profiles.user_id',
35
+                },
36
+            },
37
+        }
38
+    }
39
+    static get joiSchema() {
40
+        return Joi.object({
41
+            profile_id: Joi.number(),
42
+            user_id: Joi.number(),
43
+        })
44
+    }
45
+}

+ 25
- 0
backend/lib/models/tag-associations.js Zobrazit soubor

@@ -0,0 +1,25 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const tagSchema = require('../schemas/tags')
4
+const Tag = require('./tag')
5
+
6
+module.exports = class TagAssociation extends Schwifty.Model {
7
+    static get tableName() {
8
+        return 'tag_associations'
9
+    }
10
+    static get relationMappings() {
11
+        return {
12
+            description: {
13
+                relation: Schwifty.Model.BelongsToOneRelation,
14
+                modelClass: Tag,
15
+                join: {
16
+                    from: 'tag_associations.tag_id',
17
+                    to: 'tags.tag_id',
18
+                },
19
+            },
20
+        }
21
+    }
22
+    static get joiSchema() {
23
+        return tagSchema.association
24
+    }
25
+}

+ 11
- 0
backend/lib/models/tags.js Zobrazit soubor

@@ -0,0 +1,11 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+const tagSchema = require('../schemas/tags')
3
+
4
+module.exports = class Tag extends Schwifty.Model {
5
+    static get tableName() {
6
+        return 'tags'
7
+    }
8
+    static get joiSchema() {
9
+        return tagSchema.single
10
+    }
11
+}

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