90 lines
1.7 KiB
JavaScript
90 lines
1.7 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 goc = sequelize.define(
|
|
'goc',
|
|
{
|
|
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,
|
|
},
|
|
);
|
|
|
|
goc.associate = (db) => {
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
db.goc.hasMany(db.users, {
|
|
as: 'users_goc',
|
|
foreignKey: {
|
|
name: 'gocId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.goc.hasMany(db.aggregators, {
|
|
as: 'aggregators_goc',
|
|
foreignKey: {
|
|
name: 'gocId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.goc.hasMany(db.game_histories, {
|
|
as: 'game_histories_goc',
|
|
foreignKey: {
|
|
name: 'gocId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.goc.hasMany(db.player_profiles, {
|
|
as: 'player_profiles_goc',
|
|
foreignKey: {
|
|
name: 'gocId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.goc.hasMany(db.technical_support_logs, {
|
|
as: 'technical_support_logs_goc',
|
|
foreignKey: {
|
|
name: 'gocId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
//end loop
|
|
|
|
db.goc.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.goc.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return goc;
|
|
};
|