From dca47f77c9aa701aa50bb7bb63f4998cc2de78db Mon Sep 17 00:00:00 2001 From: eskoniarek <98158467+eskoniarek@users.noreply.github.com> Date: Wed, 1 May 2024 09:35:52 +0200 Subject: [PATCH] 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) --- .../docs/content/recipes/digital-products.mdx | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/www/apps/docs/content/recipes/digital-products.mdx b/www/apps/docs/content/recipes/digital-products.mdx index 340dfaf355..7591987f7e 100644 --- a/www/apps/docs/content/recipes/digital-products.mdx +++ b/www/apps/docs/content/recipes/digital-products.mdx @@ -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 const urls = [] - for (const item of order.items) { - const productMedias = await productMediaService - .retrieveMediasByVariant(item.variant) - if (!productMedias.length) { - return - } + for (const item of order.items) { + const productMedias = await productMediaService + .retrieveMediasByVariant(item.variant) + const downloadUrls = await Promise.all( + productMedias.map(async (productMedia) => { + + // get the download URL from the file service + return await fileService.getPresignedDownloadUrl({ + fileKey: productMedia.file_key, + isPrivate: true, + }) + }) + ) - await Promise.all([ - productMedias.forEach( - async (productMedia) => { - // get the download URL from the file service - const downloadUrl = await - fileService.getPresignedDownloadUrl({ - fileKey: productMedia.file_key, - isPrivate: true, - }) - - urls.push(downloadUrl) - }), - ]) - } - - if (!urls.length) { - return + urls.push(...downloadUrls) } sendgridService.sendEmail({