32498/backend/src/db/models/components.js
2025-07-10 15:37:35 +00:00

320 lines
6.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 components = sequelize.define(
'components',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
gas_line: {
type: DataTypes.ENUM,
values: ['CSPIPE', 'MENTION'],
},
vacuum_line: {
type: DataTypes.ENUM,
values: ['UPVC', 'CPVC', 'MENTION'],
},
water_line: {
type: DataTypes.ENUM,
values: ['MSERW', 'MENTION'],
},
solution_line: {
type: DataTypes.ENUM,
values: ['UPVC', 'CPVC', 'HDPE', 'MSRL', 'MENTION'],
},
pressure_switch_on_each_manifold: {
type: DataTypes.ENUM,
values: ['YES', 'NO', 'MENTION'],
},
chlorinator_isolation_valve: {
type: DataTypes.ENUM,
values: [
'CSBALLVALVE',
'UPVCBALLVALVE',
'CPVCBALLVALVE',
'MOTORIZEDCSBALLVALVE',
'MOTORIZEDUPVCBALLVALVE',
'MOTORIZEDCPVCBALLVALVE',
'MENTION',
],
},
vacuum_switch_on_vacuum_line: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
pressure_switch_delivery_line: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
gating_valve_on_delivery_line: {
type: DataTypes.ENUM,
values: [
'CIBUTTERFLYVALVE',
'CIBALLVALVE',
'CIGATEVALVE',
'MOTORIZEDCIBUTTERFLYVALVE',
'MOTORIZEDCIBALLVALVE',
'MOTORIZEDCIGATEVALVE',
'MENTION',
],
},
gating_valve_at_injector_inlet: {
type: DataTypes.ENUM,
values: [
'CIBUTTERFLYVALVE',
'CIBALLVALVE',
'CIGATEVALVE',
'MOTORIZEDCIBUTTERFLYVALVE',
'MOTORIZEDCIBALLVALVE',
'MOTORIZEDCIGATEVALVE',
'MENTION',
],
},
mention1: {
type: DataTypes.INTEGER,
},
mention2: {
type: DataTypes.INTEGER,
},
mention3: {
type: DataTypes.INTEGER,
},
mention4: {
type: DataTypes.INTEGER,
},
mention5: {
type: DataTypes.INTEGER,
},
isolation_valve_for_diffuser: {
type: DataTypes.INTEGER,
},
pressure_transmitter_on_manifold: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
temperature_indicator_on_manifold: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
vacuum_transmitter_on_each_vacuum_line: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
pressure_transmitter_on_delivery_line: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
flow_transmitter_on_delivery_line: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
temperature_indicator_on_individual_gas_line: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
check_valve_on_individual_solution_line: {
type: DataTypes.ENUM,
values: ['YES', 'NO'],
},
pressure_switch_on_common_suction_header: {
type: DataTypes.INTEGER,
},
pressure_indicator_on_common_suction_header: {
type: DataTypes.INTEGER,
},
basket_strainer_on_common_suction_header: {
type: DataTypes.INTEGER,
},
pressure_switch_on_each_individual_suction_line: {
type: DataTypes.INTEGER,
},
pressure_transmitter_on_individual_suction_line: {
type: DataTypes.INTEGER,
},
interconnecting_header_on_delivery_line: {
type: DataTypes.INTEGER,
},
valve_on_interconnecting_header: {
type: DataTypes.INTEGER,
},
full_hood_for_connected_tonners: {
type: DataTypes.INTEGER,
},
frp_frontal_hood_for_storage_tonners: {
type: DataTypes.INTEGER,
},
full_hood_for_storage_tonners: {
type: DataTypes.INTEGER,
},
valve_at_common_header_suction_line: {
type: DataTypes.TEXT,
},
basket_strainer_at_common_header_suction_line: {
type: DataTypes.TEXT,
},
isolation_valve_for_basket_strainer: {
type: DataTypes.TEXT,
},
gating_valve_at_individual_suction_line: {
type: DataTypes.ENUM,
values: ['CIBUTTERFLYVALVE', 'CIBALLVALVE', 'CIGATEVALVE', 'MENTION'],
},
y_type_strainer_at_individual_suction_line: {
type: DataTypes.ENUM,
values: ['CI', 'MENTION'],
},
basket_strainer_at_individual_suction_line: {
type: DataTypes.ENUM,
values: ['CI', 'MENTION'],
},
gating_valve_at_injector_outlet: {
type: DataTypes.ENUM,
values: [
'UPVCBUTTERFLYVALVE',
'UPVCBALLVALVE',
'CPVCBUTTERFLYVALVE',
'CPVCBALLVALVE',
'MENTION',
],
},
check_valve_at_injector_outlet: {
type: DataTypes.ENUM,
values: ['UPVCCHECKVALVE', 'CPVCCHECKVALVE', 'MENTION'],
},
gating_valve_for_diffuser_isolation: {
type: DataTypes.ENUM,
values: ['UPVCBALLVALVE', 'CPVCBALLVALVE', 'MENTION'],
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
components.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.components.belongsTo(db.rfqs, {
as: 'rfq',
foreignKey: {
name: 'rfqId',
},
constraints: false,
});
db.components.belongsTo(db.users, {
as: 'createdBy',
});
db.components.belongsTo(db.users, {
as: 'updatedBy',
});
};
return components;
};