From 38373faa35367c354fd94c3c5458107cf47de463 Mon Sep 17 00:00:00 2001 From: Linnea Myllynen Date: Fri, 17 Jun 2022 09:48:46 +0300 Subject: [PATCH] fix endpoint for marking taskgroups done --- src/taskGroups.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/taskGroups.js b/src/taskGroups.js index b8063b7..242b80e 100644 --- a/src/taskGroups.js +++ b/src/taskGroups.js @@ -11,19 +11,23 @@ app.post( isGroupLeader, async (req, res) => { try { - const userIds = req.body - const promises = userIds.map((user_guid) => - Promise.resolve( - postTaskGroupEntry({ - user_guid, - created_by: req.user.membernumber, - taskgroup_guid: req.params.taskgroup_guid, - completed: 'COMPLETED', - group_leader_name: req.body.group_leader_name, - }) + const userData = req.body + const promises = Object.values(userData.groups).map((userIds) => { + const promises = userIds.map((user_guid) => + Promise.resolve( + postTaskGroupEntry({ + user_guid: Number(user_guid), + created_by: Number(req.user.membernumber), + taskgroup_guid: req.params.taskgroup_guid, + completed: 'COMPLETED', + group_leader_name: userData.group_leader_name, + }) + ) ) - ) - const entries = await Promise.all(promises) + return promises + }) + const iterablePromises = [].concat.apply([], promises) + const entries = await Promise.all(iterablePromises) res.json(entries).status(200) } catch (e) { res.status(e.statusCode).send(e.message)