39230-vm/backend/src/db/models/study_plan_items.js
2026-03-18 00:00:49 +00:00

202 lines
2.3 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 study_plan_items = sequelize.define(
'study_plan_items',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
item_type: {
type: DataTypes.ENUM,
values: [
"read",
"watch",
"practice",
"flashcards",
"quiz",
"project",
"review"
],
},
scheduled_start_at: {
type: DataTypes.DATE,
},
scheduled_end_at: {
type: DataTypes.DATE,
},
status: {
type: DataTypes.ENUM,
values: [
"todo",
"in_progress",
"done",
"skipped"
],
},
estimated_minutes: {
type: DataTypes.INTEGER,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
study_plan_items.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.study_plan_items.belongsTo(db.study_plans, {
as: 'study_plan',
foreignKey: {
name: 'study_planId',
},
constraints: false,
});
db.study_plan_items.belongsTo(db.subjects, {
as: 'subject',
foreignKey: {
name: 'subjectId',
},
constraints: false,
});
db.study_plan_items.belongsTo(db.topics, {
as: 'topic',
foreignKey: {
name: 'topicId',
},
constraints: false,
});
db.study_plan_items.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.study_plan_items.belongsTo(db.users, {
as: 'createdBy',
});
db.study_plan_items.belongsTo(db.users, {
as: 'updatedBy',
});
};
return study_plan_items;
};