ready to test

Testing

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-06-22 10:06:58 +08:00
parent bf48c95467
commit 439bb33f77
189 changed files with 17559 additions and 686 deletions
+17
View File
@@ -0,0 +1,17 @@
'use strict';
const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db.config');
const mdl_Category = sequelize.define('Category', {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING(100), allowNull: false, unique: true },
slug: { type: DataTypes.STRING(120), allowNull: false, unique: true },
description: { type: DataTypes.TEXT, allowNull: true },
is_active: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true },
}, {
tableName: 'categories',
timestamps: true,
paranoid: true,
});
module.exports = mdl_Category;
+27
View File
@@ -0,0 +1,27 @@
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const Certificate = sequelize.define("Certificate", {
certificate_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: DataTypes.UUID, allowNull: false, defaultValue: DataTypes.UUIDV4, unique: true },
cert_no: { type: DataTypes.STRING(25), allowNull: false, unique: true },
ref_no: { type: DataTypes.STRING(50), allowNull: false },
user_id: { type: DataTypes.BIGINT, allowNull: false },
course_id: { type: DataTypes.BIGINT, allowNull: false },
instructors: { type: DataTypes.TEXT, allowNull: true },
score: { type: DataTypes.INTEGER, allowNull: true },
length_str: { type: DataTypes.STRING(50), allowNull: true },
issued_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
}, {
tableName: "certificates",
timestamps: true,
createdAt: "created_at",
updatedAt: "updated_at",
indexes: [
{ unique: true, fields: ["user_id", "course_id"] },
{ fields: ["uuid"] },
{ fields: ["cert_no"] },
],
});
module.exports = Certificate;
+21
View File
@@ -0,0 +1,21 @@
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const CourseInstructor = sequelize.define("CourseInstructor", {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
user_id: { type: DataTypes.BIGINT, allowNull: true },
display_name: { type: DataTypes.STRING(255), allowNull: false },
order_index: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 },
created_by: { type: DataTypes.BIGINT, allowNull: true },
}, {
tableName: "course_instructors",
timestamps: true,
createdAt: "created_at",
updatedAt: "updated_at",
indexes: [
{ fields: ["course_id"] },
],
});
module.exports = CourseInstructor;
+26
View File
@@ -0,0 +1,26 @@
'use strict';
const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db.config');
const mdl_Product = require('./products.mdl');
const mdl_CoursePurchase = sequelize.define('CoursePurchase', {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
user_id: { type: DataTypes.BIGINT, allowNull: false },
product_id: { type: DataTypes.BIGINT, allowNull: false },
amount: { type: DataTypes.DECIMAL(10, 2), allowNull: false },
currency: { type: DataTypes.STRING(10), allowNull: false, defaultValue: 'USD' },
status: { type: DataTypes.ENUM('pending', 'completed', 'failed', 'cancelled', 'refunded'), allowNull: false, defaultValue: 'pending' },
provider: { type: DataTypes.STRING(50), allowNull: false, defaultValue: 'paypal' },
provider_payload: { type: DataTypes.JSONB, allowNull: true, defaultValue: {} },
expires_at: { type: DataTypes.DATE, allowNull: true },
paid_at: { type: DataTypes.DATE, allowNull: true },
}, {
tableName: 'course_purchases',
timestamps: true,
paranoid: true,
});
mdl_CoursePurchase.belongsTo(mdl_Product, { foreignKey: 'product_id', as: 'product' });
mdl_Product.hasMany(mdl_CoursePurchase, { foreignKey: 'product_id', as: 'purchases' });
module.exports = mdl_CoursePurchase;
@@ -0,0 +1,82 @@
/***********************************************************************************************************************************************************************
* File Name: course_reading_progress.mdl.js
* Type of Program: Model
* Description: Tracks a user's reading progress through a course hierarchy (course → unit → lesson).
*
* CourseReadingProgress — one row per (user, type, reference).
* UPSERT key: (user_id, type, reference_id)
* reference_id points to course.uuid | unit.uuid | lesson.uuid based on type.
* status flips in_progress → completed when the user finishes the item.
* last_accessed_at updated on every UPSERT.
*
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Jun. 21, 2026
***********************************************************************************************************************************************************************/
const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db.config');
const CourseReadingProgress = sequelize.define('CourseReadingProgress', {
progress_id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
user_id: {
type: DataTypes.BIGINT,
allowNull: false,
references: { model: 'users', key: 'user_id' },
onDelete: 'CASCADE',
},
course_id: {
type: DataTypes.BIGINT,
allowNull: false,
references: { model: 'courses', key: 'course_id' },
onDelete: 'CASCADE',
},
reference_id: {
type: DataTypes.UUID,
allowNull: false,
comment: 'uuid of the course | unit | lesson depending on type.',
},
type: {
type: DataTypes.ENUM('course', 'unit', 'lesson'),
allowNull: false,
},
status: {
type: DataTypes.ENUM('in_progress', 'completed'),
allowNull: false,
defaultValue: 'in_progress',
},
completed_at: {
type: DataTypes.DATE,
allowNull: true,
comment: 'Set when status flips to completed. Null while in_progress.',
},
last_accessed_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: 'Updated on every UPSERT.',
},
// ── Audit trails ────────────────────────────────────────────────────────
createdBy: { type: DataTypes.BIGINT, allowNull: true },
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
}, {
tableName: 'course_reading_progress',
timestamps: true,
paranoid: false, // progress rows are never soft-deleted
indexes: [
{
unique: true,
fields: ['user_id', 'type', 'reference_id'],
name: 'uq_crp_user_type_reference',
},
{ fields: ['user_id'], name: 'idx_crp_user_id' },
{ fields: ['course_id'], name: 'idx_crp_course_id' },
{ fields: ['type'], name: 'idx_crp_type' },
{ fields: ['status'], name: 'idx_crp_status' },
],
});
module.exports = CourseReadingProgress;
+30 -7
View File
@@ -1,6 +1,6 @@
// models/courses/associations.js
const { Course, CourseProduct, CourseRole, CourseProductCategory } = require("./courses.mdl");
const { Course, CourseProductCategory } = require("./courses.mdl");
const Unit = require("./units.mdl");
const Lesson = require("./lessons.mdl");
const LessonPage = require("./lesson_page.mdl");
@@ -12,6 +12,17 @@ const UnitQuiz = require("./unit_quiz.mdl");
const QuizQuestion = require("./quiz_question.mdl");
const QuizOption = require("./quiz_option.mdl");
const mdl_Users = require("../users/users.mdl");
const QuizAttempt = require("./quiz_attempt.mdl");
const mdl_Category = require("./categories.mdl");
const Certificate = require("./certificate.mdl");
const CourseInstructor = require("./course_instructor.mdl");
const CourseReadingProgress = require("./course_reading_progress.mdl");
// ── CourseReadingProgress ─────────────────────────────────────────────────────
CourseReadingProgress.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
CourseReadingProgress.belongsTo(Course, { foreignKey: 'course_id', as: 'course' });
mdl_Users.hasMany(CourseReadingProgress, { foreignKey: 'user_id', as: 'courseReadingProgress' });
Course.hasMany(CourseReadingProgress, { foreignKey: 'course_id', as: 'readingProgress' });
// ── Course ────────────────────────────────────────────────────────────────────
Course.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
@@ -19,10 +30,13 @@ Course.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
Course.hasMany(Unit, { as: "units", foreignKey: "course_id" });
Course.hasMany(CourseObjective, { as: "objectives", foreignKey: "course_id" });
Course.hasMany(CoursePrerequisite, { as: "prerequisites", foreignKey: "course_id" });
Course.hasOne(CourseAssessment, { as: "assessment", foreignKey: "course_id" });
Course.hasMany(CourseProduct, { as: "products", foreignKey: "course_id" });
Course.hasMany(CourseRole, { as: "roles", foreignKey: "course_id" });
Course.hasMany(CourseProductCategory, { as: "categories", 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" });
CourseInstructor.belongsTo(Course, { as: "course", foreignKey: "course_id" });
CourseInstructor.belongsTo(mdl_Users, { as: "user", foreignKey: "user_id" });
Course.belongsToMany(mdl_Category, { through: CourseProductCategory, foreignKey: 'course_id', otherKey: 'category_id', as: 'categories' });
mdl_Category.belongsToMany(Course, { through: CourseProductCategory, foreignKey: 'category_id', otherKey: 'course_id', as: 'courses' });
// ── Unit ──────────────────────────────────────────────────────────────────────
Unit.belongsTo(Course, { as: "course", foreignKey: "course_id" });
@@ -58,10 +72,19 @@ QuizQuestion.hasMany(QuizOption, { as: "options", foreignKey: "question_id" });
// ── QuizOption ────────────────────────────────────────────────────────────────
QuizOption.belongsTo(QuizQuestion, { as: "question", foreignKey: "question_id" });
// ── QuizAttempt ───────────────────────────────────────────────────────────────
QuizAttempt.belongsTo(UnitQuiz, { as: "quiz", foreignKey: "quiz_id" });
QuizAttempt.belongsTo(CourseAssessment, { as: "assessment", foreignKey: "assessment_id" });
QuizAttempt.belongsTo(mdl_Users, { as: "user", foreignKey: "user_id" });
UnitQuiz.hasMany(QuizAttempt, { as: "attempts", foreignKey: "quiz_id" });
CourseAssessment.hasMany(QuizAttempt, { as: "attempts", foreignKey: "assessment_id" });
module.exports = {
Course, CourseProduct, CourseRole, CourseProductCategory,
Course, CourseProductCategory,
Unit, Lesson, LessonPage,
CourseObjective, LessonObjective,
CoursePrerequisite, CourseAssessment,
UnitQuiz, QuizQuestion, QuizOption,
UnitQuiz, QuizQuestion, QuizOption, QuizAttempt,
mdl_Category, Certificate, CourseInstructor,
CourseReadingProgress,
};
-14
View File
@@ -22,18 +22,6 @@ const Course = sequelize.define("Course", {
// ── Junction Tables ───────────────────────────────────────────────────────────
const CourseProduct = sequelize.define("CourseProduct", {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
product_id: { type: DataTypes.BIGINT, allowNull: false },
}, { tableName: "course_products", timestamps: true });
const CourseRole = sequelize.define("CourseRole", {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
role_id: { type: DataTypes.BIGINT, allowNull: false },
}, { tableName: "course_roles", timestamps: true });
const CourseProductCategory = sequelize.define("CourseProductCategory", {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
@@ -42,7 +30,5 @@ const CourseProductCategory = sequelize.define("CourseProductCategory", {
module.exports = {
Course,
CourseProduct,
CourseRole,
CourseProductCategory,
};
+25
View File
@@ -0,0 +1,25 @@
'use strict';
const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db.config');
const { Course } = require('./courses.mdl');
const mdl_Product = sequelize.define('Product', {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
name: { type: DataTypes.STRING(200), allowNull: false },
description: { type: DataTypes.TEXT, allowNull: true },
price: { type: DataTypes.DECIMAL(10, 2), allowNull: false },
currency: { type: DataTypes.STRING(10), allowNull: false, defaultValue: 'USD' },
access_days: { type: DataTypes.INTEGER, allowNull: true },
is_active: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true },
}, {
tableName: 'products',
timestamps: true,
paranoid: true,
});
// A course has one product listing; a product belongs to one course
mdl_Product.belongsTo(Course, { foreignKey: 'course_id', as: 'course' });
Course.hasOne(mdl_Product, { foreignKey: 'course_id', as: 'product' });
module.exports = mdl_Product;
+24
View File
@@ -0,0 +1,24 @@
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const QuizAttempt = sequelize.define("QuizAttempt", {
attempt_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, unique: true },
user_id: { type: DataTypes.BIGINT, allowNull: false },
// polymorphic: belongs to either unit_quiz OR course_assessment
quiz_id: { type: DataTypes.BIGINT, allowNull: true }, // → unit_quizzes
assessment_id: { type: DataTypes.BIGINT, allowNull: true }, // → course_assessments
course_id: { type: DataTypes.BIGINT, allowNull: true }, // denormalized — for fast per-course queries
answers: { type: DataTypes.JSONB, allowNull: false, defaultValue: {} },
attempt_number: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 1 }, // 1-based per user+quiz
total_points: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 },
earned_points: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 },
score: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 }, // percentage 0-100
passing_score: { type: DataTypes.INTEGER, allowNull: true }, // snapshot at submit time
passed: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false },
}, {
tableName: "quiz_attempts",
timestamps: true,
});
module.exports = QuizAttempt;