서예진

models/ .js files

module.exports = (sequelize, DataTypes) => (
sequelize.define('auction', {
bid: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
},
msg: {
type: DataTypes.STRING(100),
allowNull: true,
},
}, {
timestamps: true,
paranoid: true,
})
);
module.exports = (sequelize, DataTypes) => (
sequelize.define('good', {
name: {
type: DataTypes.STRING(40),
allowNull: false,
},
img: {
type: DataTypes.STRING(200),
allowNull: true,
},
price: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
},
}, {
timestamps: true,
paranoid: true,
})
);
const Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development';
const config = require('../config/config')[env];
const db = {};
const sequelize = new Sequelize(
config.database, config.username, config.password, config,
);
db.sequelize = sequelize;
db.Sequelize = Sequelize;
db.User = require('./user')(sequelize, Sequelize);
db.Good = require('./good')(sequelize, Sequelize);
db.Auction = require('./auction')(sequelize, Sequelize);
db.Good.belongsTo(db.User, { as: 'owner' });
db.Good.belongsTo(db.User, { as: 'sold' });
db.User.hasMany(db.Auction);
db.Good.hasMany(db.Auction);
db.Auction.belongsTo(db.User);
db.Auction.belongsTo(db.Good);
module.exports = db;
module.exports = (sequelize, DataTypes) => (
sequelize.define('user', {
email: {
type: DataTypes.STRING(40),
allowNull: false,
unique: true,
},
nick: {
type: DataTypes.STRING(15),
allowNull: false,
},
password: {
type: DataTypes.STRING(100),
allowNull: true,
},
money: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
},
}, {
timestamps: true,
paranoid: true,
})
);