mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
61 lines
3.3 KiB
JavaScript
61 lines
3.3 KiB
JavaScript
/***********************************************************************************************************************************************************************
|
|
* 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', 'watch_video', 'listen_audio'),
|
|
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;
|