40226-vm/backend/src/db/models/prediction_submissions.js
2026-06-07 22:17:56 +00:00

170 lines
2.4 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 prediction_submissions = sequelize.define(
'prediction_submissions',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
status: {
type: DataTypes.ENUM,
values: [
"draft",
"submitted",
"locked"
],
},
submitted_at: {
type: DataTypes.DATE,
},
sheet_spreadsheet_id: {
type: DataTypes.TEXT,
},
sheet_tab_name: {
type: DataTypes.TEXT,
},
sheet_row_key: {
type: DataTypes.TEXT,
},
sheet_sync_enabled: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
last_sheet_sync_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
prediction_submissions.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.prediction_submissions.hasMany(db.match_predictions, {
as: 'match_predictions_submission',
foreignKey: {
name: 'submissionId',
},
constraints: false,
});
db.prediction_submissions.hasMany(db.open_question_answers, {
as: 'open_question_answers_submission',
foreignKey: {
name: 'submissionId',
},
constraints: false,
});
//end loop
db.prediction_submissions.belongsTo(db.friend_groups, {
as: 'friend_group',
foreignKey: {
name: 'friend_groupId',
},
constraints: false,
});
db.prediction_submissions.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.prediction_submissions.belongsTo(db.users, {
as: 'createdBy',
});
db.prediction_submissions.belongsTo(db.users, {
as: 'updatedBy',
});
};
return prediction_submissions;
};