31852/backend/src/db/models/rankings.js
2025-05-29 20:55:59 +00:00

78 lines
1.5 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 rankings = sequelize.define(
'rankings',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
wins: {
type: DataTypes.INTEGER,
},
points: {
type: DataTypes.INTEGER,
},
set_ratio: {
type: DataTypes.DECIMAL,
},
point_ratio: {
type: DataTypes.DECIMAL,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
rankings.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.rankings.belongsTo(db.teams, {
as: 'team',
foreignKey: {
name: 'teamId',
},
constraints: false,
});
db.rankings.belongsTo(db.leagues, {
as: 'league',
foreignKey: {
name: 'leagueId',
},
constraints: false,
});
db.rankings.belongsTo(db.users, {
as: 'createdBy',
});
db.rankings.belongsTo(db.users, {
as: 'updatedBy',
});
};
return rankings;
};