diff --git a/src/stories/hubbles_law/database.ts b/src/stories/hubbles_law/database.ts index f3d6441..65c7d92 100644 --- a/src/stories/hubbles_law/database.ts +++ b/src/stories/hubbles_law/database.ts @@ -320,7 +320,7 @@ async function getClassIDsForSyncClass(classID: number): Promise { return classIDs; } -export async function getMergedIDsForClass(classID: number): Promise { +export async function getMergedIDsForClass(classID: number, ignoreMergeOrder=false): Promise { // TODO: Currently this uses two queries: // The first to get the merge group (if there is one) // Then a second to get all of the classes in the merge group @@ -334,14 +334,15 @@ export async function getMergedIDsForClass(classID: number): Promise { return [classID]; } - const mergeEntries = await HubbleClassMergeGroup.findAll({ - where: { - group_id: mergeGroup.group_id, - merge_order: { - [Op.lte] : mergeGroup.merge_order, - } - } - }); + const where: WhereOptions = { + group_id: mergeGroup.group_id, + }; + if (!ignoreMergeOrder) { + where.merge_order = { + [Op.lte]: mergeGroup.merge_order, + }; + } + const mergeEntries = await HubbleClassMergeGroup.findAll({ where }); return mergeEntries.map(entry => entry.class_id); } diff --git a/src/stories/hubbles_law/router.ts b/src/stories/hubbles_law/router.ts index 1443a62..b9f134d 100644 --- a/src/stories/hubbles_law/router.ts +++ b/src/stories/hubbles_law/router.ts @@ -401,6 +401,7 @@ router.get(["/class-measurements/:studentID", "stage-3-measurements/:studentID"] router.get("/merged-classes/:classID", async (req, res) => { const classID = Number(req.params.classID); + const ignoreMergeOrder = (req.query?.ignore_merge_order as string)?.toLowerCase() === "true"; const cls = await findClassById(classID); if (cls === null) { res.status(404).json({ @@ -408,7 +409,7 @@ router.get("/merged-classes/:classID", async (req, res) => { }); return; } - const classIDs = await getMergedIDsForClass(classID); + const classIDs = await getMergedIDsForClass(classID, ignoreMergeOrder); res.json({ merged_class_ids: classIDs, });