192 lines
4.2 KiB
JavaScript
192 lines
4.2 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 sessions = sequelize.define(
|
|
'sessions',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
session_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
values: ['TypeA', 'TypeB', 'TypeC'],
|
|
},
|
|
|
|
session_date: {
|
|
type: DataTypes.DATE,
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
sessions.associate = (db) => {
|
|
db.sessions.belongsToMany(db.calls, {
|
|
as: 'sung_calls',
|
|
foreignKey: {
|
|
name: 'sessions_sung_callsId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsSung_callsCalls',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.calls, {
|
|
as: 'sung_calls_filter',
|
|
foreignKey: {
|
|
name: 'sessions_sung_callsId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsSung_callsCalls',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.songs, {
|
|
as: 'played_songs',
|
|
foreignKey: {
|
|
name: 'sessions_played_songsId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsPlayed_songsSongs',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.songs, {
|
|
as: 'played_songs_filter',
|
|
foreignKey: {
|
|
name: 'sessions_played_songsId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsPlayed_songsSongs',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.stories, {
|
|
as: 'told_stories',
|
|
foreignKey: {
|
|
name: 'sessions_told_storiesId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsTold_storiesStories',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.stories, {
|
|
as: 'told_stories_filter',
|
|
foreignKey: {
|
|
name: 'sessions_told_storiesId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsTold_storiesStories',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.calls, {
|
|
as: 'additional_calls',
|
|
foreignKey: {
|
|
name: 'sessions_additional_callsId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsAdditional_callsCalls',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.calls, {
|
|
as: 'additional_calls_filter',
|
|
foreignKey: {
|
|
name: 'sessions_additional_callsId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsAdditional_callsCalls',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.members, {
|
|
as: 'present_members',
|
|
foreignKey: {
|
|
name: 'sessions_present_membersId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsPresent_membersMembers',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.members, {
|
|
as: 'present_members_filter',
|
|
foreignKey: {
|
|
name: 'sessions_present_membersId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsPresent_membersMembers',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.members, {
|
|
as: 'visitors',
|
|
foreignKey: {
|
|
name: 'sessions_visitorsId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsVisitorsMembers',
|
|
});
|
|
|
|
db.sessions.belongsToMany(db.members, {
|
|
as: 'visitors_filter',
|
|
foreignKey: {
|
|
name: 'sessions_visitorsId',
|
|
},
|
|
constraints: false,
|
|
through: 'sessionsVisitorsMembers',
|
|
});
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
//end loop
|
|
|
|
db.sessions.belongsTo(db.users, {
|
|
as: 'leader',
|
|
foreignKey: {
|
|
name: 'leaderId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.sessions.belongsTo(db.users, {
|
|
as: 'assistant',
|
|
foreignKey: {
|
|
name: 'assistantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.sessions.belongsTo(db.users, {
|
|
as: 'representative',
|
|
foreignKey: {
|
|
name: 'representativeId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.sessions.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.sessions.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return sessions;
|
|
};
|