Skip to content

Commit 12becec

Browse files
authored
Fix cannot set headers after sent to client error (#48)
* Fix cannot set headers after sent to client error * Refactor iterating through userguids * Refactor marking tasks done
1 parent 53eafe4 commit 12becec

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ const main = async () => {
282282
const memberGroup = req.body
283283
// iterate through membergroups and user ids
284284
// Mark the task as completed for all the users
285-
for (let userIds of Object.values(memberGroup)) {
286-
const promises = userIds.map((user_guid) =>
285+
const promises = Object.values(memberGroup).map((userIds) =>
286+
userIds.map((user_guid) =>
287287
Promise.resolve(
288288
postTaskEntry({
289289
user_guid,
@@ -293,9 +293,10 @@ const main = async () => {
293293
})
294294
)
295295
)
296-
const entries = await Promise.all(promises)
297-
res.json(entries).status(200)
298-
}
296+
)
297+
const flattedPromises = promises.flat()
298+
const entries = await Promise.all(flattedPromises)
299+
res.json(entries).status(200)
299300
} catch (e) {
300301
res.status(e.statusCode).send(e.message)
301302
}

0 commit comments

Comments
 (0)