160 lines
2.1 KiB
JavaScript
160 lines
2.1 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 deals = sequelize.define(
|
|
'deals',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
deal_number: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
value: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
currency: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"Open",
|
|
|
|
|
|
"Won",
|
|
|
|
|
|
"Lost"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
close_date: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
deals.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.deals.hasMany(db.activities, {
|
|
as: 'activities_related_deal',
|
|
foreignKey: {
|
|
name: 'related_dealId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.deals.belongsTo(db.pipeline_stages, {
|
|
as: 'stage',
|
|
foreignKey: {
|
|
name: 'stageId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.deals.belongsTo(db.users, {
|
|
as: 'owner',
|
|
foreignKey: {
|
|
name: 'ownerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.deals.belongsTo(db.contacts, {
|
|
as: 'primary_contact',
|
|
foreignKey: {
|
|
name: 'primary_contactId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.deals.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.deals.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return deals;
|
|
};
|
|
|
|
|