Showing
4 changed files
with
85 additions
and
0 deletions
models/auction.js
0 → 100644
1 | +module.exports = (sequelize, DataTypes) => ( | ||
2 | + sequelize.define('auction', { | ||
3 | + bid: { | ||
4 | + type: DataTypes.INTEGER, | ||
5 | + allowNull: false, | ||
6 | + defaultValue: 0, | ||
7 | + }, | ||
8 | + msg: { | ||
9 | + type: DataTypes.STRING(100), | ||
10 | + allowNull: true, | ||
11 | + }, | ||
12 | + }, { | ||
13 | + timestamps: true, | ||
14 | + paranoid: true, | ||
15 | + }) | ||
16 | +); |
models/good.js
0 → 100644
1 | +module.exports = (sequelize, DataTypes) => ( | ||
2 | + sequelize.define('good', { | ||
3 | + name: { | ||
4 | + type: DataTypes.STRING(40), | ||
5 | + allowNull: false, | ||
6 | + }, | ||
7 | + img: { | ||
8 | + type: DataTypes.STRING(200), | ||
9 | + allowNull: true, | ||
10 | + }, | ||
11 | + price: { | ||
12 | + type: DataTypes.INTEGER, | ||
13 | + allowNull: false, | ||
14 | + defaultValue: 0, | ||
15 | + }, | ||
16 | + }, { | ||
17 | + timestamps: true, | ||
18 | + paranoid: true, | ||
19 | + }) | ||
20 | +); |
models/index.js
0 → 100644
1 | +const Sequelize = require('sequelize'); | ||
2 | + | ||
3 | +const env = process.env.NODE_ENV || 'development'; | ||
4 | +const config = require('../config/config')[env]; | ||
5 | +const db = {}; | ||
6 | + | ||
7 | +const sequelize = new Sequelize( | ||
8 | + config.database, config.username, config.password, config, | ||
9 | +); | ||
10 | + | ||
11 | +db.sequelize = sequelize; | ||
12 | +db.Sequelize = Sequelize; | ||
13 | +db.User = require('./user')(sequelize, Sequelize); | ||
14 | +db.Good = require('./good')(sequelize, Sequelize); | ||
15 | +db.Auction = require('./auction')(sequelize, Sequelize); | ||
16 | + | ||
17 | +db.Good.belongsTo(db.User, { as: 'owner' }); | ||
18 | +db.Good.belongsTo(db.User, { as: 'sold' }); | ||
19 | +db.User.hasMany(db.Auction); | ||
20 | +db.Good.hasMany(db.Auction); | ||
21 | +db.Auction.belongsTo(db.User); | ||
22 | +db.Auction.belongsTo(db.Good); | ||
23 | + | ||
24 | +module.exports = db; |
models/user.js
0 → 100644
1 | +module.exports = (sequelize, DataTypes) => ( | ||
2 | + sequelize.define('user', { | ||
3 | + email: { | ||
4 | + type: DataTypes.STRING(40), | ||
5 | + allowNull: false, | ||
6 | + unique: true, | ||
7 | + }, | ||
8 | + nick: { | ||
9 | + type: DataTypes.STRING(15), | ||
10 | + allowNull: false, | ||
11 | + }, | ||
12 | + password: { | ||
13 | + type: DataTypes.STRING(100), | ||
14 | + allowNull: true, | ||
15 | + }, | ||
16 | + money: { | ||
17 | + type: DataTypes.INTEGER, | ||
18 | + allowNull: false, | ||
19 | + defaultValue: 0, | ||
20 | + }, | ||
21 | + }, { | ||
22 | + timestamps: true, | ||
23 | + paranoid: true, | ||
24 | + }) | ||
25 | +); |
-
Please register or login to post a comment