37925-vm/backend/src/db/models/productions.js
2026-01-28 19:33:03 +00:00

151 lines
1.9 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
const productions = sequelize.define(
'productions',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
reference: {
type: DataTypes.TEXT,
},
quantity: {
type: DataTypes.INTEGER,
},
status: {
type: DataTypes.ENUM,
values: [
"planned",
"in_progress",
"completed",
"cancelled"
],
},
start_date: {
type: DataTypes.DATE,
},
end_date: {
type: DataTypes.DATE,
},
note: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
productions.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.productions.belongsTo(db.warehouses, {
as: 'production_unit',
foreignKey: {
name: 'production_unitId',
},
constraints: false,
});
db.productions.belongsTo(db.items, {
as: 'product',
foreignKey: {
name: 'productId',
},
constraints: false,
});
db.productions.belongsTo(db.users, {
as: 'performed_by',
foreignKey: {
name: 'performed_byId',
},
constraints: false,
});
db.productions.belongsTo(db.users, {
as: 'createdBy',
});
db.productions.belongsTo(db.users, {
as: 'updatedBy',
});
};
return productions;
};