rentease-backend/models/Room.js

95 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;