38333-vm/backend/src/db/models/safety_checklists.js
2026-02-10 01:48:44 +00:00

138 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 safety_checklists = sequelize.define(
'safety_checklists',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
status: {
type: DataTypes.ENUM,
values: [
"draft",
"submitted",
"approved",
"rejected"
],
},
items_json: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
safety_checklists.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.safety_checklists.belongsTo(db.job_requests, {
as: 'job_request',
foreignKey: {
name: 'job_requestId',
},
constraints: false,
});
db.safety_checklists.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.safety_checklists.hasMany(db.file, {
as: 'attachments',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.safety_checklists.getTableName(),
belongsToColumn: 'attachments',
},
});
db.safety_checklists.belongsTo(db.users, {
as: 'createdBy',
});
db.safety_checklists.belongsTo(db.users, {
as: 'updatedBy',
});
};
return safety_checklists;
};