Newer
Older

Louis
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const timestamps = require('./properties/timestamps')
module.exports = (sequelize, DataTypes) => {
const Model = sequelize.define('BundleCode', Object.assign(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
validate: {
isUUID: 4,
},
},
name: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
platforms: {
type: DataTypes.JSONB,
},
meta: {
type: DataTypes.JSONB,
},
},
timestamps(DataTypes),
), {
paranoid: true,
tableName: 'bundle_codes',
})
Model.getPolyIdentifier = () => 'bundle_code'
Model.getRelationIdentifier = () => 'bundle_codes'
Model.prototype.toJSON = function userToJSON() {
return {
id: this.id,
name: this.name,
description: this.description,
platforms: this.platforms,
meta: this.meta,
created_at: this.created_at,
updated_at: this.updated_at,
}
}
Model.associate = function defineModelAssociations(models) {
Model.belongsToMany(models.User, { through: 'user_bundle_codes', foreignKey: 'bundle_code_id', otherKey: 'user_id', timestamps: false })
}
Model.relations = []
return Model
}