Files
nxxmdata/government-backend/models/WarehouseTransaction.js

60 lines
1.2 KiB
JavaScript
Raw Normal View History

2025-09-24 17:49:32 +08:00
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Material = require('./Material');
const WarehouseTransaction = sequelize.define('WarehouseTransaction', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
materialId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: Material,
key: 'id'
},
comment: '物资ID'
},
type: {
type: DataTypes.STRING,
allowNull: false,
validate: {
isIn: [['in', 'out']]
},
comment: '操作类型in(入库)out(出库)'
},
quantity: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
min: 1
},
comment: '操作数量'
},
operator: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人'
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
comment: '备注'
}
}, {
tableName: 'warehouse_transactions',
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true
});
// 定义关系
WarehouseTransaction.belongsTo(Material, {
foreignKey: 'materialId',
as: 'material'
});
module.exports = WarehouseTransaction;