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

Modify dashboard group classes endpoint to return class data #94

Merged
merged 2 commits into from
Oct 20, 2023
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
14 changes: 12 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,21 @@ export async function getQuestionsForStory(storyName: string, newestOnly=true):
}


export async function getDashboardGroupClasses(code: string): Promise<number[] | null> {
export async function getDashboardGroupClasses(code: string): Promise<Class[] | null> {
const group = await DashboardClassGroup.findOne({ where: { code } });
if (group === null) {
return null;
}
const classIDs = group.class_ids;
return isNumberArray(classIDs) ? classIDs : [];
if (!isNumberArray(classIDs)) {
return [];
}
return Class.findAll({
where: {
id: {
[Op.in]: classIDs
}
}
});

}
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,15 +655,15 @@ app.put("/options/:studentID", async (req, res) => {
});

app.get("/dashboard-group-classes/:code", async (req, res) => {
const classIDs = await getDashboardGroupClasses(req.params.code);
if (classIDs === null) {
const classes= await getDashboardGroupClasses(req.params.code);
if (classes === null) {
res.statusCode = 404;
res.json({
error: `Could not find a dashboard group for code ${req.params.code}`
});
} else {
res.json({
class_ids: classIDs
classes
});
}
});