211 lines
2.8 KiB
JavaScript
211 lines
2.8 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 leagues = sequelize.define(
|
|
'leagues',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
season_label: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
start_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
end_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"upcoming",
|
|
|
|
|
|
"active",
|
|
|
|
|
|
"completed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
rosters_locked: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
registration_fee: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
rules_notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
leagues.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.leagues.hasMany(db.league_teams, {
|
|
as: 'league_teams_league',
|
|
foreignKey: {
|
|
name: 'leagueId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.leagues.hasMany(db.games, {
|
|
as: 'games_league',
|
|
foreignKey: {
|
|
name: 'leagueId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.leagues.hasMany(db.league_payments, {
|
|
as: 'league_payments_league',
|
|
foreignKey: {
|
|
name: 'leagueId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.leagues.hasMany(db.league_standings, {
|
|
as: 'league_standings_league',
|
|
foreignKey: {
|
|
name: 'leagueId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.leagues.hasMany(db.league_finish_awards, {
|
|
as: 'league_finish_awards_league',
|
|
foreignKey: {
|
|
name: 'leagueId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.leagues.belongsTo(db.clubs, {
|
|
as: 'club',
|
|
foreignKey: {
|
|
name: 'clubId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.leagues.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.leagues.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.leagues.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return leagues;
|
|
};
|
|
|
|
|