Files
starr-philproperties/apps/api/models/courses/units.mdl.js
T

28 lines
1.7 KiB
JavaScript

const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
// Standalone entity — no course_id / order_index here. A Unit is attached to
// zero or more Courses through course_units, where per-course ordering lives.
const Unit = sequelize.define("Unit", {
unit_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, hidden: true, order: 0, filterable: false },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true, hidden: true, order: 0, filterable: false },
title: { type: DataTypes.STRING(255), allowNull: false, label: "Title", hidden: false, order: 1, filterable: true },
// order 2 is reserved for the computed "Affiliated" (course_count) column, order 3 for computed "Course Status" — see UNIT_LIST_COMPUTED in units.controller.js
subscription: { type: DataTypes.STRING(50), allowNull: true, label: "Subscription", hidden: false, order: 4, filterable: true, comment: "Optional direct tier gate for standalone units — null means open (or gated only via an attached course)." },
description: { type: DataTypes.TEXT, allowNull: true, label: "Description", hidden: true, order: 0, filterable: false },
duration_seconds: { type: DataTypes.INTEGER, allowNull: true, defaultValue: 0, hidden: false, order: 5, filterable: false },
createdBy: { type: DataTypes.BIGINT, allowNull: true, filterable: true },
updatedBy: { type: DataTypes.BIGINT, allowNull: true, filterable: true },
deletedBy: { type: DataTypes.BIGINT, allowNull: true, filterable: true },
}, {
tableName: "units",
timestamps: true,
paranoid: true,
indexes: [
{ fields: ["uuid"] },
{ fields: ["deletedAt"] },
],
});
module.exports = Unit;