202 lines
2.6 KiB
JavaScript
202 lines
2.6 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 calendar_events = sequelize.define(
|
|
'calendar_events',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
provider_event_id: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
start_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
end_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
location: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"confirmed",
|
|
|
|
|
|
"tentative",
|
|
|
|
|
|
"canceled"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
last_synced_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
calendar_events.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.calendar_events.belongsTo(db.tenants, {
|
|
as: 'tenant',
|
|
foreignKey: {
|
|
name: 'tenantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.calendar_events.belongsTo(db.calendar_accounts, {
|
|
as: 'calendar_account',
|
|
foreignKey: {
|
|
name: 'calendar_accountId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.calendar_events.belongsTo(db.deals, {
|
|
as: 'deal',
|
|
foreignKey: {
|
|
name: 'dealId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.calendar_events.belongsTo(db.contacts, {
|
|
as: 'contact',
|
|
foreignKey: {
|
|
name: 'contactId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.calendar_events.belongsTo(db.tasks, {
|
|
as: 'task',
|
|
foreignKey: {
|
|
name: 'taskId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.calendar_events.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.calendar_events.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.calendar_events.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return calendar_events;
|
|
};
|
|
|
|
|