39502-vm/backend/src/db/models/whatsapp_scenarios.js
2026-04-06 13:11:07 +00:00

160 lines
2.2 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 whatsapp_scenarios = sequelize.define(
'whatsapp_scenarios',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
is_looping: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
is_sound_enabled: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
student_display_name: {
type: DataTypes.TEXT,
},
bot_display_name: {
type: DataTypes.TEXT,
},
capture_target: {
type: DataTypes.ENUM,
values: [
"google_sheet_row_preview",
"internal_lead"
],
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
whatsapp_scenarios.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.whatsapp_scenarios.hasMany(db.whatsapp_messages, {
as: 'whatsapp_messages_scenario',
foreignKey: {
name: 'scenarioId',
},
constraints: false,
});
//end loop
db.whatsapp_scenarios.belongsTo(db.sections, {
as: 'section',
foreignKey: {
name: 'sectionId',
},
constraints: false,
});
db.whatsapp_scenarios.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.whatsapp_scenarios.belongsTo(db.users, {
as: 'createdBy',
});
db.whatsapp_scenarios.belongsTo(db.users, {
as: 'updatedBy',
});
};
return whatsapp_scenarios;
};