95 lines
2.2 KiB
JavaScript
95 lines
2.2 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
||
const sequelize = require('../config/db');
|
||
const Apartment = require('./Apartment');
|
||
|
||
const Room = sequelize.define('Room', {
|
||
id: {
|
||
type: DataTypes.INTEGER,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '房间ID'
|
||
},
|
||
apartmentId: {
|
||
type: DataTypes.INTEGER,
|
||
allowNull: false,
|
||
references: {
|
||
model: Apartment,
|
||
key: 'id'
|
||
},
|
||
comment: '所属公寓ID'
|
||
},
|
||
roomNumber: {
|
||
type: DataTypes.STRING(20),
|
||
allowNull: false,
|
||
comment: '房间编号'
|
||
},
|
||
area: {
|
||
type: DataTypes.DECIMAL(10, 2),
|
||
allowNull: true,
|
||
comment: '房间面积'
|
||
},
|
||
monthlyPrice: {
|
||
type: DataTypes.DECIMAL(10, 2),
|
||
allowNull: true,
|
||
comment: '月租金'
|
||
},
|
||
yearlyPrice: {
|
||
type: DataTypes.DECIMAL(10, 2),
|
||
allowNull: true,
|
||
comment: '年租金'
|
||
},
|
||
status: {
|
||
type: DataTypes.ENUM('empty', 'reserved', 'rented'),
|
||
allowNull: false,
|
||
defaultValue: 'empty',
|
||
comment: '房间状态(empty:空房,reserved:预订,rented:在租)'
|
||
},
|
||
subStatus: {
|
||
type: DataTypes.ENUM('normal', 'soon_expire', 'expired'),
|
||
allowNull: false,
|
||
defaultValue: 'normal',
|
||
comment: '附属状态(normal:正常,soon_expire:即将到期,expired:已到期)'
|
||
},
|
||
otherStatus: {
|
||
type: DataTypes.ENUM('', 'cleaning', 'maintenance'),
|
||
allowNull: false,
|
||
defaultValue: '',
|
||
comment: '其他状态(cleaning:打扫中,maintenance:维修中)'
|
||
},
|
||
createBy: {
|
||
type: DataTypes.INTEGER,
|
||
allowNull: true,
|
||
comment: '创建人ID'
|
||
},
|
||
createTime: {
|
||
type: DataTypes.DATE,
|
||
defaultValue: DataTypes.NOW,
|
||
comment: '创建时间'
|
||
},
|
||
updateBy: {
|
||
type: DataTypes.INTEGER,
|
||
allowNull: true,
|
||
comment: '修改人ID'
|
||
},
|
||
updateTime: {
|
||
type: DataTypes.DATE,
|
||
defaultValue: DataTypes.NOW,
|
||
onUpdate: DataTypes.NOW,
|
||
comment: '更新时间'
|
||
},
|
||
isDeleted: {
|
||
type: DataTypes.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '删除状态(0:未删除,1:已删除)'
|
||
}
|
||
}, {
|
||
tableName: 'rooms',
|
||
timestamps: false
|
||
});
|
||
|
||
// 建立关联
|
||
Room.belongsTo(Apartment, { foreignKey: 'apartmentId' });
|
||
Apartment.hasMany(Room, { foreignKey: 'apartmentId' });
|
||
|
||
module.exports = Room; |