This commit is contained in:
rgrgogu
2026-05-20 13:22:29 +08:00
parent 6907e9bb2d
commit 6a5145f553
26 changed files with 2615 additions and 221 deletions
+16
View File
@@ -0,0 +1,16 @@
"use strict";
/**
* Replace all junction rows for a course in one shot (delete + bulk create).
*/
async function syncJunction(Model, courseId, ids, fkField, transaction) {
await Model.destroy({ where: { course_id: courseId }, transaction });
if (ids?.length) {
await Model.bulkCreate(
ids.map((id) => ({ course_id: courseId, [fkField]: id })),
{ transaction }
);
}
}
module.exports = { syncJunction };