39280-vm/backend/src/db/models/cognitive_exercises.js
2026-03-23 16:25:45 +00:00

197 lines
2.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 cognitive_exercises = sequelize.define(
'cognitive_exercises',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
exercise_name: {
type: DataTypes.TEXT,
},
exercise_type: {
type: DataTypes.ENUM,
values: [
"memory",
"attention",
"language",
"orientation",
"executive_function"
],
},
instructions: {
type: DataTypes.TEXT,
},
difficulty_level: {
type: DataTypes.ENUM,
values: [
"easy",
"medium",
"hard",
"adaptive"
],
},
max_score: {
type: DataTypes.INTEGER,
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
cognitive_exercises.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.cognitive_exercises.hasMany(db.cognitive_attempts, {
as: 'cognitive_attempts_exercise',
foreignKey: {
name: 'exerciseId',
},
constraints: false,
});
//end loop
db.cognitive_exercises.belongsTo(db.cognitive_programs, {
as: 'program',
foreignKey: {
name: 'programId',
},
constraints: false,
});
db.cognitive_exercises.belongsTo(db.accounts, {
as: 'accounts',
foreignKey: {
name: 'accountsId',
},
constraints: false,
});
db.cognitive_exercises.hasMany(db.file, {
as: 'assets',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.cognitive_exercises.getTableName(),
belongsToColumn: 'assets',
},
});
db.cognitive_exercises.belongsTo(db.users, {
as: 'createdBy',
});
db.cognitive_exercises.belongsTo(db.users, {
as: 'updatedBy',
});
};
return cognitive_exercises;
};