39141-vm/backend/src/db/models/conversation_threads.js
2026-03-11 19:54:10 +00:00

124 lines
1.8 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 conversation_threads = sequelize.define(
'conversation_threads',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
state: {
type: DataTypes.ENUM,
values: [
"open",
"resolved",
"archived"
],
},
last_message_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
conversation_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.conversation_threads.hasMany(db.messages, {
as: 'messages_thread',
foreignKey: {
name: 'threadId',
},
constraints: false,
});
//end loop
db.conversation_threads.belongsTo(db.projects, {
as: 'project',
foreignKey: {
name: 'projectId',
},
constraints: false,
});
db.conversation_threads.belongsTo(db.users, {
as: 'initiator',
foreignKey: {
name: 'initiatorId',
},
constraints: false,
});
db.conversation_threads.belongsTo(db.users, {
as: 'createdBy',
});
db.conversation_threads.belongsTo(db.users, {
as: 'updatedBy',
});
};
return conversation_threads;
};