40491-vm/backend/src/db/models/contact_messages.js
2026-07-27 17:59:14 +00:00

162 lines
2.0 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 contact_messages = sequelize.define(
'contact_messages',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
sender_name: {
type: DataTypes.TEXT,
},
sender_email: {
type: DataTypes.TEXT,
},
sender_phone: {
type: DataTypes.TEXT,
},
subject: {
type: DataTypes.TEXT,
},
message: {
type: DataTypes.TEXT,
},
status: {
type: DataTypes.ENUM,
values: [
"new",
"in_progress",
"replied",
"archived"
],
},
received_at: {
type: DataTypes.DATE,
},
replied_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
contact_messages.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.contact_messages.belongsTo(db.users, {
as: 'assigned_to',
foreignKey: {
name: 'assigned_toId',
},
constraints: false,
});
db.contact_messages.hasMany(db.file, {
as: 'attachments',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.contact_messages.getTableName(),
belongsToColumn: 'attachments',
},
});
db.contact_messages.belongsTo(db.users, {
as: 'createdBy',
});
db.contact_messages.belongsTo(db.users, {
as: 'updatedBy',
});
};
return contact_messages;
};