feat(utils): Introduce promiseAll util (#5543)

This commit is contained in:
Adrien de Peretti
2023-11-08 08:48:48 +01:00
committed by GitHub
parent e4ce2f4e07
commit f90ba02087
99 changed files with 464 additions and 297 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ import {
WithRequiredProperty,
} from "@medusajs/types"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { DALUtils, isDefined, MedusaError } from "@medusajs/utils"
import { DALUtils, isDefined, MedusaError, promiseAll } from "@medusajs/utils"
import { ProductServiceTypes } from "../types/services"
@@ -228,7 +228,7 @@ export class ProductRepository extends DALUtils.MikroOrmAbstractBaseRepository<P
productsToUpdate.map((product) => [product.id, product])
)
const products = await Promise.all(
const products = await promiseAll(
data.map(async (updateData) => {
const product = productsToUpdateMap.get(updateData.id)
@@ -61,6 +61,7 @@ import {
mapObjectTo,
MedusaContext,
MedusaError,
promiseAll,
} from "@medusajs/utils"
import {
entityNameToLinkableKeysMap,
@@ -734,7 +735,7 @@ export default class ProductModuleService<
ProductTypes.CreateProductOptionDTO[]
>()
const productsData = await Promise.all(
const productsData = await promiseAll(
data.map(async (product) => {
const productData = { ...product }
if (!productData.handle) {
@@ -816,7 +817,7 @@ export default class ProductModuleService<
})
}
await Promise.all(
await promiseAll(
[...productVariantsMap].map(async ([handle, variants]) => {
return await this.productVariantService_.create(
productByHandleMap.get(handle)!,
@@ -861,7 +862,7 @@ export default class ProductModuleService<
const productOptionsMap = new Map<string, TProductOption[]>()
const productsData = await Promise.all(
const productsData = await promiseAll(
data.map(async (product) => {
const { variants, ...productData } = product
@@ -997,7 +998,7 @@ export default class ProductModuleService<
)
}
await Promise.all(promises)
await promiseAll(promises)
return products
}