mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
added new requirements for lessons and units
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: completion_requirement.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Admin-configured rule describing what "complete" means for a course, unit, or lesson.
|
||||
*
|
||||
* CompletionRequirement — polymorphic via (entity_type, entity_id); entity_id is the BIGINT PK of the
|
||||
* owning courses/units/lessons row (not a UUID reference like TaskRequirement —
|
||||
* this row is OWNED by the entity, not pointing at an arbitrary target).
|
||||
* type dispatches through utils/courses/completion_requirements.registry.js.
|
||||
* Multiple rows on one entity are AND'd together by services/courses/completion.service.js.
|
||||
*
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jul. 14, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const CompletionRequirement = sequelize.define('CompletionRequirement', {
|
||||
requirement_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
entity_type: {
|
||||
type: DataTypes.ENUM('course', 'unit', 'lesson'),
|
||||
allowNull: false,
|
||||
filterable: true,
|
||||
},
|
||||
entity_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
comment: 'course_id | unit_id | lesson_id depending on entity_type. No DB-level FK (polymorphic across 3 tables).',
|
||||
filterable: true,
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.ENUM('read_all_content', 'pass_quiz', 'watch_percent', 'manual_complete'),
|
||||
allowNull: false,
|
||||
filterable: true,
|
||||
},
|
||||
|
||||
// ── watch_percent ───────────────────────────────────────────────────────
|
||||
min_percent: { type: DataTypes.INTEGER, allowNull: true, comment: 'watch_percent only — minimum % of media watched.', filterable: false },
|
||||
|
||||
// ── manual_complete ─────────────────────────────────────────────────────
|
||||
button_label: { type: DataTypes.STRING, allowNull: true, comment: 'manual_complete only — optional custom CTA text.', filterable: false },
|
||||
|
||||
is_required: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true, filterable: true },
|
||||
order: { type: DataTypes.INTEGER, defaultValue: 0, filterable: true },
|
||||
|
||||
// ── Audit trails ────────────────────────────────────────────────────────
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
deletedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
}, {
|
||||
tableName: 'completion_requirements',
|
||||
paranoid: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
module.exports = CompletionRequirement;
|
||||
Reference in New Issue
Block a user