Skip to content

Commit

Permalink
Merge pull request #43 from partio-scout/fix/mark-taskgroups-done
Browse files Browse the repository at this point in the history
fix endpoint for marking taskgroups done
  • Loading branch information
linneamyl authored Jun 17, 2022
2 parents 3d67bf1 + 38373fa commit 353855f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/taskGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 353855f

Please sign in to comment.