Skip to content

Commit

Permalink
Fix cannot set headers after sent to client error (#48)
Browse files Browse the repository at this point in the history
* Fix cannot set headers after sent to client error

* Refactor iterating through userguids

* Refactor marking tasks done
  • Loading branch information
linneamyl authored Sep 5, 2022
1 parent 53eafe4 commit 12becec
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ const main = async () => {
const memberGroup = req.body
// iterate through membergroups and user ids
// Mark the task as completed for all the users
for (let userIds of Object.values(memberGroup)) {
const promises = userIds.map((user_guid) =>
const promises = Object.values(memberGroup).map((userIds) =>
userIds.map((user_guid) =>
Promise.resolve(
postTaskEntry({
user_guid,
Expand All @@ -293,9 +293,10 @@ const main = async () => {
})
)
)
const entries = await Promise.all(promises)
res.json(entries).status(200)
}
)
const flattedPromises = promises.flat()
const entries = await Promise.all(flattedPromises)
res.json(entries).status(200)
} catch (e) {
res.status(e.statusCode).send(e.message)
}
Expand Down

0 comments on commit 12becec

Please sign in to comment.