/*********************************************************************************************************************************************************************** * File Name: pending_certificate.mdl.js * Type of Program: Model * Description: Holds certificates queued for issuance after a 5-minute delay * following a passed course assessment. The cron job * (cron/jobs/issue_certificates.cron.js) runs hourly on the hour * and processes rows where issue_at <= NOW(). * * Author: Kenneth Obsequio (@lash0000) * Date Created: Jun. 24, 2026 ***********************************************************************************************************************************************************************/ const { DataTypes } = require('sequelize'); const sequelize = require('../../config/db.config'); const PendingCertificate = sequelize.define('PendingCertificate', { pending_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true }, user_id: { type: DataTypes.BIGINT, allowNull: false }, course_id: { type: DataTypes.BIGINT, allowNull: false }, course_uuid: { type: DataTypes.STRING(36), allowNull: false }, course_title: { type: DataTypes.TEXT, allowNull: true }, passed_at: { type: DataTypes.DATE, allowNull: false }, issue_at: { type: DataTypes.DATE, allowNull: false }, processed_at: { type: DataTypes.DATE, allowNull: true }, }, { tableName: 'pending_certificates', timestamps: true, indexes: [ { fields: ['user_id'] }, { fields: ['issue_at'] }, { unique: true, fields: ['user_id', 'course_id'] }, ], }); module.exports = PendingCertificate;