Files
yunrui_asset/backend/models/ConsumableRecord.js
T
zhang1106 63f0cb570e refactor: 统一代码风格并迁移至 ESLint 新配置
style(backend): 格式化模型文件代码
style(frontend): 调整组件代码格式
chore: 删除旧 ESLint 配置并添加新配置
refactor(backend): 重构模型定义语法
style: 统一箭头函数和对象属性简写
2026-03-27 19:12:16 +08:00

77 lines
1.6 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Consumable = require('./Consumable');
const ConsumableRecord = sequelize.define(
'ConsumableRecord',
{
recordId: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
allowNull: false,
},
consumableId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Consumable,
key: 'consumableId',
},
},
type: {
type: DataTypes.ENUM('in', 'out'),
allowNull: false,
},
quantity: {
type: DataTypes.INTEGER,
allowNull: false,
},
previousStock: {
type: DataTypes.INTEGER,
allowNull: false,
},
currentStock: {
type: DataTypes.INTEGER,
allowNull: false,
},
operator: {
type: DataTypes.STRING,
allowNull: false,
},
reason: {
type: DataTypes.STRING,
},
recipient: {
type: DataTypes.STRING,
},
notes: {
type: DataTypes.TEXT,
},
snList: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: '本次操作的SN序列号列表',
},
},
{
tableName: 'consumable_records',
timestamps: true,
indexes: [{ fields: ['consumableId'] }, { fields: ['type'] }, { fields: ['createdAt'] }],
}
);
ConsumableRecord.belongsTo(Consumable, {
foreignKey: 'consumableId',
as: 'consumable',
onDelete: 'CASCADE',
});
Consumable.hasMany(ConsumableRecord, {
foreignKey: 'consumableId',
as: 'records',
onDelete: 'CASCADE',
});
module.exports = ConsumableRecord;