add: more things

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-04 03:35:09 +08:00
parent a572c1e25f
commit 3c13bb9821
36 changed files with 896 additions and 928 deletions
+45
View File
@@ -0,0 +1,45 @@
"use strict";
const { Op } = require("sequelize");
const onlyDeleted = { deletedAt: { [Op.not]: null } };
/**
* Permanently delete a single archived record.
* Returns the record on success, null if not found, false if found but not archived.
*
* @param {Model} Model - Sequelize model
* @param {object} where - Where clause (primary key lookup)
* @param {object} t - Sequelize transaction
*/
async function permanentDeleteOne(Model, where, t) {
const record = await Model.findOne({ where, paranoid: false, transaction: t });
if (!record) return null;
if (!record.deletedAt) return false;
await record.destroy({ force: true, transaction: t });
return record;
}
/**
* Permanently delete many archived records by primary key.
* Returns the count of deleted records.
*
* @param {Model} Model - Sequelize model
* @param {string} pkColumn - Primary key column name (e.g. "course_id")
* @param {Array} ids - Array of primary key values to delete
* @param {object} t - Sequelize transaction
*/
async function permanentDeleteMany(Model, pkColumn, ids, t) {
if (!ids?.length) return 0;
const count = await Model.destroy({
where: { [pkColumn]: ids, ...onlyDeleted },
transaction: t,
paranoid: false,
force: true,
});
return count;
}
module.exports = { permanentDeleteOne, permanentDeleteMany };