mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
16 lines
431 B
JavaScript
16 lines
431 B
JavaScript
"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 }; |