chore: relocate backend into apps/api ahead of monorepo merge

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-24 12:20:40 +08:00
co-authored by Claude Sonnet 5
parent af44598df6
commit eaa6d2276a
388 changed files with 0 additions and 13998 deletions
@@ -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 };