Skip to content

Commit

Permalink
Merge pull request #159 from Carifio24/ignore-merge-order
Browse files Browse the repository at this point in the history
Allow ignoring merge order when fetching merged classes
  • Loading branch information
Carifio24 authored Nov 4, 2024
2 parents 8aa55ac + 34c4006 commit 760825a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/stories/hubbles_law/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ async function getClassIDsForSyncClass(classID: number): Promise<number[]> {
return classIDs;
}

export async function getMergedIDsForClass(classID: number): Promise<number[]> {
export async function getMergedIDsForClass(classID: number, ignoreMergeOrder=false): Promise<number[]> {
// 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
Expand All @@ -334,14 +334,15 @@ export async function getMergedIDsForClass(classID: number): Promise<number[]> {
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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/stories/hubbles_law/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,15 @@ 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({
message: `No class found with ID ${classID}`,
});
return;
}
const classIDs = await getMergedIDsForClass(classID);
const classIDs = await getMergedIDsForClass(classID, ignoreMergeOrder);
res.json({
merged_class_ids: classIDs,
});
Expand Down

0 comments on commit 760825a

Please sign in to comment.