From 9ea0815d8070200a6f6a4607d79ac3f5190b02a2 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Thu, 19 Oct 2023 16:59:05 -0400 Subject: [PATCH 1/2] Modify dashboard group classes endpoint to return class data. --- src/database.ts | 14 ++++++++++++-- src/server.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/database.ts b/src/database.ts index 6eb85a1..33bcd38 100644 --- a/src/database.ts +++ b/src/database.ts @@ -665,11 +665,21 @@ export async function getQuestionsForStory(storyName: string, newestOnly=true): } -export async function getDashboardGroupClasses(code: string): Promise { +export async function getDashboardGroupClasses(code: string): Promise { 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 + } + } + }); + } diff --git a/src/server.ts b/src/server.ts index 36d199f..a68e9b5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -663,7 +663,7 @@ app.get("/dashboard-group-classes/:code", async (req, res) => { }); } else { res.json({ - class_ids: classIDs + classes: classIDs }); } }); From 9dcb2a2c252fd354759ab023379c51399167d50b Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Thu, 19 Oct 2023 17:03:36 -0400 Subject: [PATCH 2/2] Rename variable. --- src/server.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server.ts b/src/server.ts index a68e9b5..d746e2d 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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({ - classes: classIDs + classes }); } });