40328-vm/backend/src/db/models/question_choices.js
2026-06-25 03:17:00 +00:00

106 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 question_choices = sequelize.define(
'question_choices',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
position: {
type: DataTypes.INTEGER,
},
label: {
type: DataTypes.TEXT,
},
value: {
type: DataTypes.TEXT,
},
is_other: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
question_choices.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.question_choices.belongsTo(db.survey_questions, {
as: 'question',
foreignKey: {
name: 'questionId',
},
constraints: false,
});
db.question_choices.belongsTo(db.users, {
as: 'createdBy',
});
db.question_choices.belongsTo(db.users, {
as: 'updatedBy',
});
};
return question_choices;
};