2026-03-03 22:04:15 +00:00

222 lines
2.6 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,
},
title: {
type: DataTypes.TEXT,
},
slug: {
type: DataTypes.TEXT,
},
game_type: {
type: DataTypes.ENUM,
values: [
"slots",
"roulette",
"blackjack",
"poker",
"crash",
"sports_demo",
"other"
],
},
status: {
type: DataTypes.ENUM,
values: [
"draft",
"published",
"disabled"
],
},
min_bet: {
type: DataTypes.DECIMAL,
},
max_bet: {
type: DataTypes.DECIMAL,
},
currency: {
type: DataTypes.TEXT,
},
rtp_percent: {
type: DataTypes.INTEGER,
},
provider_name: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
released_at: {
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
db.games.hasMany(db.game_sessions, {
as: 'game_sessions_game',
foreignKey: {
name: 'gameId',
},
constraints: false,
});
db.games.hasMany(db.game_rounds, {
as: 'game_rounds_game',
foreignKey: {
name: 'gameId',
},
constraints: false,
});
//end loop
db.games.hasMany(db.file, {
as: 'cover_image',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.games.getTableName(),
belongsToColumn: 'cover_image',
},
});
db.games.hasMany(db.file, {
as: 'game_client_file',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.games.getTableName(),
belongsToColumn: 'game_client_file',
},
});
db.games.belongsTo(db.users, {
as: 'createdBy',
});
db.games.belongsTo(db.users, {
as: 'updatedBy',
});
};
return games;
};