232 lines
2.8 KiB
JavaScript
232 lines
2.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 lead_contacts = sequelize.define(
|
|
'lead_contacts',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
contact_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
company_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
industry: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"healthcare",
|
|
|
|
|
|
"financial_services",
|
|
|
|
|
|
"engineering",
|
|
|
|
|
|
"professional_services",
|
|
|
|
|
|
"government_state_local",
|
|
|
|
|
|
"non_profit",
|
|
|
|
|
|
"education",
|
|
|
|
|
|
"manufacturing",
|
|
|
|
|
|
"legal",
|
|
|
|
|
|
"real_estate",
|
|
|
|
|
|
"technology",
|
|
|
|
|
|
"other"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
corporate_email: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
privacy_consent: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
consent_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
lead_status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"new",
|
|
|
|
|
|
"qualified",
|
|
|
|
|
|
"needs_follow_up",
|
|
|
|
|
|
"scheduled",
|
|
|
|
|
|
"closed_won",
|
|
|
|
|
|
"closed_lost",
|
|
|
|
|
|
"do_not_contact"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
lead_temperature: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
lead_contacts.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.lead_contacts.hasMany(db.webhook_transmissions, {
|
|
as: 'webhook_transmissions_lead_contact',
|
|
foreignKey: {
|
|
name: 'lead_contactId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.lead_contacts.belongsTo(db.diagnostic_assessments, {
|
|
as: 'assessment',
|
|
foreignKey: {
|
|
name: 'assessmentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.lead_contacts.belongsTo(db.users, {
|
|
as: 'assigned_owner',
|
|
foreignKey: {
|
|
name: 'assigned_ownerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.lead_contacts.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.lead_contacts.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.lead_contacts.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return lead_contacts;
|
|
};
|
|
|
|
|