Files
nxxmdata/government-backend/models/WarehouseTransaction.js
2025-09-24 17:49:32 +08:00

60 lines
1.2 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/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;