37431-vm/backend/src/db/models/work_centers.js
2026-01-13 11:35:23 +00:00

188 lines
2.1 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 work_centers = sequelize.define(
'work_centers',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
work_center_name: {
type: DataTypes.TEXT,
},
work_center_code: {
type: DataTypes.TEXT,
},
center_type: {
type: DataTypes.ENUM,
values: [
"assembly",
"machining",
"packaging",
"inspection",
"warehouse",
"utilities"
],
},
capacity_units_per_hour: {
type: DataTypes.DECIMAL,
},
status: {
type: DataTypes.ENUM,
values: [
"active",
"inactive"
],
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
work_centers.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.work_centers.hasMany(db.operations, {
as: 'operations_work_center',
foreignKey: {
name: 'work_centerId',
},
constraints: false,
});
db.work_centers.hasMany(db.machines, {
as: 'machines_work_center',
foreignKey: {
name: 'work_centerId',
},
constraints: false,
});
//end loop
db.work_centers.belongsTo(db.plants, {
as: 'plant',
foreignKey: {
name: 'plantId',
},
constraints: false,
});
db.work_centers.belongsTo(db.users, {
as: 'createdBy',
});
db.work_centers.belongsTo(db.users, {
as: 'updatedBy',
});
};
return work_centers;
};