173 lines
2.2 KiB
JavaScript
173 lines
2.2 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 open_questions = sequelize.define(
|
|
'open_questions',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
question_text: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
question_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"short_text",
|
|
|
|
|
|
"long_text",
|
|
|
|
|
|
"number",
|
|
|
|
|
|
"single_choice"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
stage_scope: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"pre_tournament",
|
|
|
|
|
|
"group_stage",
|
|
|
|
|
|
"knockout_stage",
|
|
|
|
|
|
"anytime"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
order_index: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_required: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
help_text: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
open_questions.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.open_questions.hasMany(db.open_question_choices, {
|
|
as: 'open_question_choices_open_question',
|
|
foreignKey: {
|
|
name: 'open_questionId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.open_questions.hasMany(db.open_question_answers, {
|
|
as: 'open_question_answers_open_question',
|
|
foreignKey: {
|
|
name: 'open_questionId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.open_questions.belongsTo(db.tournaments, {
|
|
as: 'tournament',
|
|
foreignKey: {
|
|
name: 'tournamentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.open_questions.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.open_questions.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return open_questions;
|
|
};
|
|
|
|
|