Skip to content

Commit

Permalink
Merge pull request #94 from Carifio24/class-groups-more-data
Browse files Browse the repository at this point in the history
Modify dashboard group classes endpoint to return class data
  • Loading branch information
patudom authored Oct 20, 2023
2 parents e15e63b + 9dcb2a2 commit 829f33e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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
});
}
});

0 comments on commit 829f33e

Please sign in to comment.