Skip to content

Commit

Permalink
Added userId support
Browse files Browse the repository at this point in the history
  • Loading branch information
AydanPirani committed Jul 7, 2024
1 parent 2504dd8 commit 8977e06
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/services/s3/s3-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ s3Router.get(
);

s3Router.get(
"/download/batch/:USERID",
"/download/batch/",
RoleChecker([Role.Enum.STAFF, Role.Enum.CORPORATE], false),
s3ClientMiddleware,
async (req, res, next) => {
Expand All @@ -77,19 +77,27 @@ s3Router.get(

const batchDownloadPromises = userIds.map((userId) =>
getResumeUrl(userId, s3)
.then((url) => ({ userId, url: url }))
.catch(() => ({ userId, url: null }))
);
const batchDownloadUrls = await Promise.allSettled(

const batchDownloadResults = await Promise.allSettled(
batchDownloadPromises
);

const filteredUrls = batchDownloadUrls.forEach((result) => {
const filteredUrls = batchDownloadResults.forEach((result) => {
if (result.status === "fulfilled") {
return result.value;
}
});

return res.status(StatusCodes.OK).send({ url: filteredUrls });
const errors = batchDownloadResults.filter(
(result) => result.status === "rejected"
).length;

return res
.status(StatusCodes.OK)
.send({ data: filteredUrls, errorCount: errors });
} catch (error) {
next(error);
}
Expand Down

0 comments on commit 8977e06

Please sign in to comment.