Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ignoring merge order when fetching merged classes #159

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/stories/hubbles_law/database.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Attributes, FindOptions, Op, QueryTypes, Sequelize, WhereAttributeHash, WhereOptions, col, fn, literal } from "sequelize";
import { AsyncMergedHubbleStudentClasses, Galaxy, HubbleMeasurement, SampleHubbleMeasurement, SyncMergedHubbleClasses } from "./models";
import { classSize, findClassById, findStudentById } from "../../database";

Check warning on line 3 in src/stories/hubbles_law/database.ts

View workflow job for this annotation

GitHub Actions / build

'classSize' is defined but never used. Allowed unused vars must match /^_/u
import { RemoveHubbleMeasurementResult, SubmitHubbleMeasurementResult } from "./request_results";
import { Class, StoryState, Student, StudentsClasses } from "../../models";
import { HubbleStudentData } from "./models/hubble_student_data";
Expand Down Expand Up @@ -320,7 +320,7 @@
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 @@
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
Loading