mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
course,tasklist,task and completed validation
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -33,7 +33,7 @@ const CompletionRequirement = sequelize.define('CompletionRequirement', {
|
||||
filterable: true,
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.ENUM('read_all_content', 'pass_quiz', 'watch_percent', 'manual_complete'),
|
||||
type: DataTypes.ENUM('read_all_content', 'pass_quiz', 'watch_percent', 'manual_complete', 'watch_video', 'listen_audio'),
|
||||
allowNull: false,
|
||||
filterable: true,
|
||||
},
|
||||
|
||||
@@ -51,7 +51,7 @@ const CompletionRequirementProgress = sequelize.define('CompletionRequirementPro
|
||||
block_progress: {
|
||||
type: DataTypes.JSONB,
|
||||
allowNull: true,
|
||||
comment: 'watch_video/listen_audio only — { [block_id]: percent } running max per matching block; completed once every current block of that type is at 100.',
|
||||
comment: 'watch_percent/watch_video/listen_audio — { [block_id]: { percent, updatedAt } } running max + last-sample timestamp per block. The timestamp lets recordWatchProgress validate a reported percent against real elapsed wall-clock time (anti-skip). watch_video/listen_audio: completed once every current block of that type is at 100. watch_percent: also keeps progress_percent as its aggregate max across whichever block reports.',
|
||||
},
|
||||
completed: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
const { DataTypes } = require("sequelize");
|
||||
const sequelize = require("../../config/db.config");
|
||||
|
||||
const CourseRole = sequelize.define("CourseRole", {
|
||||
role_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
course_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
text: { type: DataTypes.STRING(255), allowNull: false },
|
||||
order_index: { type: DataTypes.INTEGER, defaultValue: 0 },
|
||||
}, {
|
||||
tableName: "course_roles",
|
||||
timestamps: true,
|
||||
paranoid: true,
|
||||
});
|
||||
|
||||
module.exports = CourseRole
|
||||
@@ -9,6 +9,7 @@ const LessonPage = require("./lesson_page.mdl");
|
||||
const CourseObjective = require("./course_objective.mdl");
|
||||
const LessonObjective = require("./lesson_objective.mdl");
|
||||
const CoursePrerequisite = require("./course_prerequisite.mdl");
|
||||
const CourseRole = require("./course_role.mdl");
|
||||
const CourseAssessment = require("./course_assessment.mdl");
|
||||
const UnitQuiz = require("./unit_quiz.mdl");
|
||||
const QuizQuestion = require("./quiz_question.mdl");
|
||||
@@ -79,6 +80,7 @@ Course.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
|
||||
Course.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
|
||||
Course.hasMany(CourseObjective, { as: "objectives", foreignKey: "course_id" });
|
||||
Course.hasMany(CoursePrerequisite, { as: "prerequisites", foreignKey: "course_id" });
|
||||
Course.hasMany(CourseRole, { as: "roles", foreignKey: "course_id" });
|
||||
Course.hasOne(CourseAssessment, { as: "assessment", foreignKey: "course_id" });
|
||||
Course.hasMany(Certificate, { as: "certificates", foreignKey: "course_id" });
|
||||
Course.hasMany(CourseInstructor, { as: "instructors", foreignKey: "course_id" });
|
||||
@@ -142,7 +144,7 @@ module.exports = {
|
||||
Unit, Lesson, LessonPage,
|
||||
CourseUnit, UnitLesson,
|
||||
CourseObjective, LessonObjective,
|
||||
CoursePrerequisite, CourseAssessment,
|
||||
CoursePrerequisite, CourseRole, CourseAssessment,
|
||||
UnitQuiz, QuizQuestion, QuizOption, QuizAttempt,
|
||||
AssessmentSession, QuizSession,
|
||||
mdl_Category, Certificate, CourseInstructor,
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: media_playback_position.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Per-user "where did I last leave off" position for a video/audio block, entirely
|
||||
* decoupled from CompletionRequirement — tracked for ANY video/audio block regardless
|
||||
* of whether the lesson has a watch-type completion requirement configured. Powers
|
||||
* resume-on-reopen only; carries no completion/anti-cheat semantics (that's
|
||||
* CompletionRequirementProgress's job, see completion_requirement_progress.mdl.js).
|
||||
*
|
||||
* MediaPlaybackPosition — UPSERT key: (user_id, lesson_id, block_id). Last-write-wins, not a
|
||||
* ratcheted max — a deliberate rewind-and-stop should resume there, not
|
||||
* snap back to a previously-reached high-water mark.
|
||||
*
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jul. 17, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const MediaPlaybackPosition = sequelize.define('MediaPlaybackPosition', {
|
||||
position_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'users', key: 'user_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
lesson_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'lessons', key: 'lesson_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
block_id: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
comment: 'The block\'s own id within LessonPage.blocks JSONB — no DB-level FK, blocks are not their own table.',
|
||||
},
|
||||
percent: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: 'Last-known % position, 0-100. Last-write-wins — not a ratcheted max.',
|
||||
},
|
||||
}, {
|
||||
tableName: 'media_playback_positions',
|
||||
timestamps: true,
|
||||
paranoid: false, // position rows are never soft-deleted, matches CompletionRequirementProgress
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['user_id', 'lesson_id', 'block_id'],
|
||||
name: 'uq_mpp_user_lesson_block',
|
||||
},
|
||||
{ fields: ['user_id', 'lesson_id'], name: 'idx_mpp_user_lesson' },
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = MediaPlaybackPosition;
|
||||
Reference in New Issue
Block a user