215 lines
2.5 KiB
JavaScript
215 lines
2.5 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_inspection_plans = sequelize.define(
|
|
'qa_inspection_plans',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
plan_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
plan_code: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
inspection_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"incoming",
|
|
|
|
|
|
"in_process",
|
|
|
|
|
|
"final",
|
|
|
|
|
|
"audit"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
sampling_method: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"100_percent",
|
|
|
|
|
|
"aql",
|
|
|
|
|
|
"fixed_n"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
sample_size: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
plan_status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"active",
|
|
|
|
|
|
"obsolete"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
qa_inspection_plans.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.qa_inspection_plans.hasMany(db.qa_characteristics, {
|
|
as: 'qa_characteristics_inspection_plan',
|
|
foreignKey: {
|
|
name: 'inspection_planId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.qa_inspection_plans.hasMany(db.qa_inspections, {
|
|
as: 'qa_inspections_inspection_plan',
|
|
foreignKey: {
|
|
name: 'inspection_planId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.qa_inspection_plans.belongsTo(db.items, {
|
|
as: 'item',
|
|
foreignKey: {
|
|
name: 'itemId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.qa_inspection_plans.hasMany(db.file, {
|
|
as: 'attachments',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.qa_inspection_plans.getTableName(),
|
|
belongsToColumn: 'attachments',
|
|
},
|
|
});
|
|
|
|
|
|
db.qa_inspection_plans.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.qa_inspection_plans.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return qa_inspection_plans;
|
|
};
|
|
|
|
|