39091-vm/backend/src/db/models/message_threads.js
2026-03-10 14:20:13 +00:00

139 lines
1.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 message_threads = sequelize.define(
'message_threads',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
status: {
type: DataTypes.ENUM,
values: [
"open",
"pending",
"closed"
],
},
subject: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
message_threads.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.message_threads.hasMany(db.messages, {
as: 'messages_thread',
foreignKey: {
name: 'threadId',
},
constraints: false,
});
//end loop
db.message_threads.belongsTo(db.customers, {
as: 'customer',
foreignKey: {
name: 'customerId',
},
constraints: false,
});
db.message_threads.belongsTo(db.users, {
as: 'createdBy',
});
db.message_threads.belongsTo(db.users, {
as: 'updatedBy',
});
};
return message_threads;
};