2025-04-30 16:30:53 +00:00

94 lines
1.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 games = sequelize.define(
'games',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
score_team_one: {
type: DataTypes.INTEGER,
},
score_team_two: {
type: DataTypes.INTEGER,
},
start_date: {
type: DataTypes.DATE,
},
end_date: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
games.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.games.belongsTo(db.teams, {
as: 'team_one',
foreignKey: {
name: 'team_oneId',
},
constraints: false,
});
db.games.belongsTo(db.teams, {
as: 'team_two',
foreignKey: {
name: 'team_twoId',
},
constraints: false,
});
db.games.belongsTo(db.tournaments, {
as: 'tournament',
foreignKey: {
name: 'tournamentId',
},
constraints: false,
});
db.games.belongsTo(db.championship, {
as: 'championship',
foreignKey: {
name: 'championshipId',
},
constraints: false,
});
db.games.belongsTo(db.users, {
as: 'createdBy',
});
db.games.belongsTo(db.users, {
as: 'updatedBy',
});
};
return games;
};