rentease-backend-new/models/Rental.js

115 lines
2.5 KiB
JavaScript
Raw 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 Room = require('./Room');
const Renter = require('./Renter');
const Rental = sequelize.define('Rental', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '租赁记录ID'
},
roomId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: Room,
key: 'id'
},
comment: '房间ID'
},
renterId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: Renter,
key: 'id'
},
comment: '租客ID'
},
startDate: {
type: DataTypes.DATE,
allowNull: false,
comment: '开始日期'
},
endDate: {
type: DataTypes.DATE,
allowNull: false,
comment: '结束日期'
},
paymentType: {
type: DataTypes.ENUM('monthly', 'quarterly', 'half_year', 'yearly'),
allowNull: false,
defaultValue: 'monthly',
comment: '付租方式monthly月租quarterly季租half_year半年租yearly年租'
},
rent: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
comment: '租金'
},
deposit: {
type: DataTypes.DECIMAL(10, 2),
allowNull: true,
comment: '押金'
},
operator: {
type: DataTypes.STRING(50),
allowNull: true,
comment: '经办人'
},
status: {
type: DataTypes.ENUM('active', 'expired', 'terminated'),
allowNull: false,
defaultValue: 'active',
comment: '租约状态active生效中expired已到期terminated提前终止'
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
comment: '备注'
},
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: '更新时间'
},
tenantId: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '租户ID'
},
isDeleted: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '删除状态0未删除1已删除'
}
}, {
tableName: 'rentals',
timestamps: false,
comment: '租赁表'
});
// 建立关联
Rental.belongsTo(Room, { foreignKey: 'roomId' });
Rental.belongsTo(Renter, { foreignKey: 'renterId' });
module.exports = Rental;