39565-vm/backend/src/db/models/qa_results.js
2026-04-11 19:24:11 +00:00

152 lines
1.7 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 qa_results = sequelize.define(
'qa_results',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
measured_value: {
type: DataTypes.DECIMAL,
},
attribute_result: {
type: DataTypes.ENUM,
values: [
"pass",
"fail",
"na"
],
},
within_limits: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
qa_results.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.qa_results.belongsTo(db.qa_inspections, {
as: 'qa_inspection',
foreignKey: {
name: 'qa_inspectionId',
},
constraints: false,
});
db.qa_results.belongsTo(db.qa_characteristics, {
as: 'characteristic',
foreignKey: {
name: 'characteristicId',
},
constraints: false,
});
db.qa_results.belongsTo(db.users, {
as: 'createdBy',
});
db.qa_results.belongsTo(db.users, {
as: 'updatedBy',
});
};
return qa_results;
};