38477-vm/backend/src/db/models/pricing_test_runs.js
2026-02-16 11:58:41 +00:00

167 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 pricing_test_runs = sequelize.define(
'pricing_test_runs',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
tested_at: {
type: DataTypes.DATE,
},
distance_km: {
type: DataTypes.DECIMAL,
},
estimated_total: {
type: DataTypes.DECIMAL,
},
breakdown: {
type: DataTypes.TEXT,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
pricing_test_runs.associate = (db) => {
db.pricing_test_runs.belongsToMany(db.service_catalog, {
as: 'services',
foreignKey: {
name: 'pricing_test_runs_servicesId',
},
constraints: false,
through: 'pricing_test_runsServicesService_catalog',
});
db.pricing_test_runs.belongsToMany(db.service_catalog, {
as: 'services_filter',
foreignKey: {
name: 'pricing_test_runs_servicesId',
},
constraints: false,
through: 'pricing_test_runsServicesService_catalog',
});
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.pricing_test_runs.belongsTo(db.tenants, {
as: 'tenant',
foreignKey: {
name: 'tenantId',
},
constraints: false,
});
db.pricing_test_runs.belongsTo(db.users, {
as: 'requested_by',
foreignKey: {
name: 'requested_byId',
},
constraints: false,
});
db.pricing_test_runs.belongsTo(db.vehicle_types, {
as: 'vehicle_type',
foreignKey: {
name: 'vehicle_typeId',
},
constraints: false,
});
db.pricing_test_runs.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.pricing_test_runs.belongsTo(db.users, {
as: 'createdBy',
});
db.pricing_test_runs.belongsTo(db.users, {
as: 'updatedBy',
});
};
return pricing_test_runs;
};