docs: fix for subscriber logic in digital products recipe (#7184)

Update the subscriber code snippet in Digital Product recipe, to properly wait for the pre-signed URL for each item's media.

Closes [#7170 ](https://github.com/medusajs/medusa/issues/7170)
This commit is contained in:
eskoniarek
2024-05-01 07:35:52 +00:00
committed by GitHub
parent bb37e139aa
commit dca47f77c9
@@ -1003,30 +1003,21 @@ Finally, you can send a notification, such as an email, to the customer using th
// find product medias in the order // find product medias in the order
const urls = [] const urls = []
for (const item of order.items) { for (const item of order.items) {
const productMedias = await productMediaService const productMedias = await productMediaService
.retrieveMediasByVariant(item.variant) .retrieveMediasByVariant(item.variant)
if (!productMedias.length) { const downloadUrls = await Promise.all(
return productMedias.map(async (productMedia) => {
}
await Promise.all([ // get the download URL from the file service
productMedias.forEach( return await fileService.getPresignedDownloadUrl({
async (productMedia) => { fileKey: productMedia.file_key,
// get the download URL from the file service isPrivate: true,
const downloadUrl = await })
fileService.getPresignedDownloadUrl({ })
fileKey: productMedia.file_key, )
isPrivate: true,
})
urls.push(downloadUrl) urls.push(...downloadUrls)
}),
])
}
if (!urls.length) {
return
} }
sendgridService.sendEmail({ sendgridService.sendEmail({