2026-02-04 12:52:50 +00:00

161 lines
2.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 offers = sequelize.define(
'offers',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
offer_number: {
type: DataTypes.TEXT,
},
status: {
type: DataTypes.ENUM,
values: [
"draft",
"sent",
"accepted",
"rejected",
"expired"
],
},
sent_at: {
type: DataTypes.DATE,
},
accepted_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
offers.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.offers.hasMany(db.offer_versions, {
as: 'offer_versions_offer',
foreignKey: {
name: 'offerId',
},
constraints: false,
});
//end loop
db.offers.belongsTo(db.projects, {
as: 'project',
foreignKey: {
name: 'projectId',
},
constraints: false,
});
db.offers.belongsTo(db.configurations, {
as: 'configuration',
foreignKey: {
name: 'configurationId',
},
constraints: false,
});
db.offers.belongsTo(db.users, {
as: 'author_user',
foreignKey: {
name: 'author_userId',
},
constraints: false,
});
db.offers.belongsTo(db.offer_templates, {
as: 'template',
foreignKey: {
name: 'templateId',
},
constraints: false,
});
db.offers.belongsTo(db.users, {
as: 'createdBy',
});
db.offers.belongsTo(db.users, {
as: 'updatedBy',
});
};
return offers;
};