162 lines
3.3 KiB
JavaScript
162 lines
3.3 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 teams = sequelize.define(
|
|
'teams',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
teams.associate = (db) => {
|
|
db.teams.belongsToMany(db.users, {
|
|
as: 'members',
|
|
foreignKey: {
|
|
name: 'teams_membersId',
|
|
},
|
|
constraints: false,
|
|
through: 'teamsMembersUsers',
|
|
});
|
|
|
|
db.teams.belongsToMany(db.users, {
|
|
as: 'members_filter',
|
|
foreignKey: {
|
|
name: 'teams_membersId',
|
|
},
|
|
constraints: false,
|
|
through: 'teamsMembersUsers',
|
|
});
|
|
|
|
db.teams.belongsToMany(db.events, {
|
|
as: 'events',
|
|
foreignKey: {
|
|
name: 'teams_eventsId',
|
|
},
|
|
constraints: false,
|
|
through: 'teamsEventsEvents',
|
|
});
|
|
|
|
db.teams.belongsToMany(db.events, {
|
|
as: 'events_filter',
|
|
foreignKey: {
|
|
name: 'teams_eventsId',
|
|
},
|
|
constraints: false,
|
|
through: 'teamsEventsEvents',
|
|
});
|
|
|
|
db.teams.belongsToMany(db.tactics, {
|
|
as: 'tactics',
|
|
foreignKey: {
|
|
name: 'teams_tacticsId',
|
|
},
|
|
constraints: false,
|
|
through: 'teamsTacticsTactics',
|
|
});
|
|
|
|
db.teams.belongsToMany(db.tactics, {
|
|
as: 'tactics_filter',
|
|
foreignKey: {
|
|
name: 'teams_tacticsId',
|
|
},
|
|
constraints: false,
|
|
through: 'teamsTacticsTactics',
|
|
});
|
|
|
|
db.teams.belongsToMany(db.feedbacks, {
|
|
as: 'feedbacks',
|
|
foreignKey: {
|
|
name: 'teams_feedbacksId',
|
|
},
|
|
constraints: false,
|
|
through: 'teamsFeedbacksFeedbacks',
|
|
});
|
|
|
|
db.teams.belongsToMany(db.feedbacks, {
|
|
as: 'feedbacks_filter',
|
|
foreignKey: {
|
|
name: 'teams_feedbacksId',
|
|
},
|
|
constraints: false,
|
|
through: 'teamsFeedbacksFeedbacks',
|
|
});
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
db.teams.hasMany(db.events, {
|
|
as: 'events_team',
|
|
foreignKey: {
|
|
name: 'teamId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.teams.hasMany(db.feedbacks, {
|
|
as: 'feedbacks_team',
|
|
foreignKey: {
|
|
name: 'teamId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.teams.hasMany(db.tactics, {
|
|
as: 'tactics_team',
|
|
foreignKey: {
|
|
name: 'teamId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.teams.hasMany(db.tasks, {
|
|
as: 'tasks_team',
|
|
foreignKey: {
|
|
name: 'teamId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
//end loop
|
|
|
|
db.teams.belongsTo(db.equipos, {
|
|
as: 'equipos',
|
|
foreignKey: {
|
|
name: 'equiposId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.teams.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.teams.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return teams;
|
|
};
|