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