98 lines
1.9 KiB
JavaScript
98 lines
1.9 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 events = sequelize.define(
|
|
'events',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
start_time: {
|
|
type: DataTypes.DATE,
|
|
},
|
|
|
|
end_time: {
|
|
type: DataTypes.DATE,
|
|
},
|
|
|
|
event_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
values: ['entrenamiento', 'scrim', 'partido', 'charla'],
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
events.associate = (db) => {
|
|
db.events.belongsToMany(db.users, {
|
|
as: 'participants',
|
|
foreignKey: {
|
|
name: 'events_participantsId',
|
|
},
|
|
constraints: false,
|
|
through: 'eventsParticipantsUsers',
|
|
});
|
|
|
|
db.events.belongsToMany(db.users, {
|
|
as: 'participants_filter',
|
|
foreignKey: {
|
|
name: 'events_participantsId',
|
|
},
|
|
constraints: false,
|
|
through: 'eventsParticipantsUsers',
|
|
});
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
//end loop
|
|
|
|
db.events.belongsTo(db.teams, {
|
|
as: 'team',
|
|
foreignKey: {
|
|
name: 'teamId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.events.belongsTo(db.equipos, {
|
|
as: 'equipos',
|
|
foreignKey: {
|
|
name: 'equiposId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.events.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.events.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return events;
|
|
};
|