31258/backend/src/db/models/valuations.js
2025-05-05 11:15:58 +00:00

68 lines
1.4 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 valuations = sequelize.define(
'valuations',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
estimated_value: {
type: DataTypes.DECIMAL,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
valuations.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.valuations.belongsTo(db.properties, {
as: 'property',
foreignKey: {
name: 'propertyId',
},
constraints: false,
});
db.valuations.hasMany(db.file, {
as: 'report',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.valuations.getTableName(),
belongsToColumn: 'report',
},
});
db.valuations.belongsTo(db.users, {
as: 'createdBy',
});
db.valuations.belongsTo(db.users, {
as: 'updatedBy',
});
};
return valuations;
};