206 lines
2.5 KiB
JavaScript
206 lines
2.5 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 survey_invitations = sequelize.define(
|
|
'survey_invitations',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
channel: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"email",
|
|
|
|
|
|
"slack",
|
|
|
|
|
|
"teams"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"queued",
|
|
|
|
|
|
"sent",
|
|
|
|
|
|
"delivered",
|
|
|
|
|
|
"opened",
|
|
|
|
|
|
"clicked",
|
|
|
|
|
|
"bounced",
|
|
|
|
|
|
"failed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
delivery_target: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
invite_token: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
sent_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
opened_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
completed_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
survey_invitations.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.survey_invitations.hasMany(db.survey_responses, {
|
|
as: 'survey_responses_invitation',
|
|
foreignKey: {
|
|
name: 'invitationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.survey_invitations.belongsTo(db.surveys, {
|
|
as: 'survey',
|
|
foreignKey: {
|
|
name: 'surveyId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.survey_invitations.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.survey_invitations.belongsTo(db.departments, {
|
|
as: 'department',
|
|
foreignKey: {
|
|
name: 'departmentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.survey_invitations.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.survey_invitations.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.survey_invitations.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return survey_invitations;
|
|
};
|
|
|
|
|