167 lines
2.3 KiB
JavaScript
167 lines
2.3 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 client_interactions = sequelize.define(
|
|
'client_interactions',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"call",
|
|
|
|
|
|
"email",
|
|
|
|
|
|
"meeting",
|
|
|
|
|
|
"note"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
occurred_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
subject: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
details: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
client_interactions.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.client_interactions.belongsTo(db.tenants, {
|
|
as: 'tenant',
|
|
foreignKey: {
|
|
name: 'tenantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.client_interactions.belongsTo(db.clients, {
|
|
as: 'client',
|
|
foreignKey: {
|
|
name: 'clientId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.client_interactions.belongsTo(db.users, {
|
|
as: 'owner',
|
|
foreignKey: {
|
|
name: 'ownerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.client_interactions.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.client_interactions.hasMany(db.file, {
|
|
as: 'attachments',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.client_interactions.getTableName(),
|
|
belongsToColumn: 'attachments',
|
|
},
|
|
});
|
|
|
|
|
|
db.client_interactions.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.client_interactions.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return client_interactions;
|
|
};
|
|
|
|
|