-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
29 lines (25 loc) · 1.06 KB
/
models.js
File metadata and controls
29 lines (25 loc) · 1.06 KB
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
const defineModels = (db) => {
db.User = db.sequelize.define('user', {
name: {type: db.Sequelize.STRING, allowNull: false},
avatarUrl: db.Sequelize.STRING,
extra: db.Sequelize.JSONB,
});
db.Pool = db.sequelize.define('pool', {
name: {type: db.Sequelize.STRING, allowNull: false},
goalAmountValue: {type: db.Sequelize.INTEGER, allowNull: true, min: 1},
goalAmountCurrency: {type: db.Sequelize.STRING, allowNull: true},
extra: db.Sequelize.JSONB,
});
db.Contribution = db.sequelize.define('contribution', {
amountValue: {type: db.Sequelize.INTEGER, allowNull: false, min: 1},
amountCurrency: {type: db.Sequelize.STRING, allowNull: false},
note: db.Sequelize.TEXT,
extra: db.Sequelize.JSONB,
});
db.User.hasMany(db.Pool, {foreignKey: 'creatorId'});
db.Pool.belongsTo(db.User, {as: 'creator'});
db.Pool.hasMany(db.Contribution);
db.Contribution.belongsTo(db.Pool);
db.Contribution.belongsTo(db.User, {as: 'contributor'});
}
module.exports = defineModels;