Skip to content

Commit

Permalink
Tweak endpoint response format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Oct 18, 2023
1 parent c7e5dec commit f5e0a38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,10 @@ export async function getQuestionsForStory(storyName: string, newestOnly=true):
}


export async function getDashboardGroupClasses(code: string): Promise<number[]> {
export async function getDashboardGroupClasses(code: string): Promise<number[] | null> {
const group = await DashboardClassGroup.findOne({ where: { code } });
if (group === null) {
return [];
return null;
}
const classIDs = group.class_ids;
return isNumberArray(classIDs) ? classIDs : [];
Expand Down
14 changes: 10 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,14 @@ app.put("/options/:studentID", async (req, res) => {

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

0 comments on commit f5e0a38

Please sign in to comment.