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

View File

@@ -1,5 +1,6 @@
import { IInventoryService, InventoryItemDTO } from "@medusajs/types"
import { WorkflowArguments } from "../../helper"
import { promiseAll } from "@medusajs/utils"
type Result = {
tag: string
@@ -23,7 +24,7 @@ export async function createInventoryItems({
return void 0
}
return await Promise.all(
return await promiseAll(
data.inventoryItems.map(async (item) => {
const inventoryItem = await inventoryService!.createInventoryItem({
sku: item.sku!,

View File

@@ -1,5 +1,6 @@
import { InventoryItemDTO } from "@medusajs/types"
import { WorkflowArguments } from "../../helper"
import { promiseAll } from "@medusajs/utils"
export async function detachInventoryItems({
container,
@@ -21,7 +22,7 @@ export async function detachInventoryItems({
return []
}
await Promise.all(
await promiseAll(
data.inventoryItems.map(async ({ tag, inventoryItem }) => {
return await productVariantInventoryService.detachInventoryItem(
inventoryItem.id,

View File

@@ -1,4 +1,5 @@
import { WorkflowArguments } from "../../helper"
import { promiseAll } from "@medusajs/utils"
type ProductHandle = string
type SalesChannelId = string
@@ -34,7 +35,7 @@ export async function attachSalesChannelToProducts({
}
})
await Promise.all(
await promiseAll(
Array.from(salesChannelIdProductIdsMap.entries()).map(
async ([salesChannelId, productIds]) => {
return await salesChannelServiceTx.addProducts(

View File

@@ -1,4 +1,5 @@
import { WorkflowArguments } from "../../helper"
import { promiseAll } from "@medusajs/utils"
type ProductHandle = string
type ShippingProfileId = string
@@ -33,7 +34,7 @@ export async function attachShippingProfileToProducts({
}
})
await Promise.all(
await promiseAll(
Array.from(profileIdProductIdsMap.entries()).map(
async ([profileId, productIds]) => {
return await shippingProfileServiceTx.addProducts(profileId, productIds)

View File

@@ -1,4 +1,5 @@
import { WorkflowArguments } from "../../helper"
import { promiseAll } from "@medusajs/utils"
type ProductHandle = string
type SalesChannelId = string
@@ -32,7 +33,7 @@ export async function detachSalesChannelFromProducts({
}
})
await Promise.all(
await promiseAll(
Array.from(salesChannelIdProductIdsMap.entries()).map(
async ([salesChannelId, productIds]) => {
return await salesChannelServiceTx.removeProducts(

View File

@@ -1,4 +1,5 @@
import { WorkflowArguments } from "../../helper"
import { promiseAll } from "@medusajs/utils"
type ProductHandle = string
type ShippingProfileId = string
@@ -32,7 +33,7 @@ export async function detachShippingProfileFromProducts({
}
})
await Promise.all(
await promiseAll(
Array.from(profileIdProductIdsMap.entries()).map(
async ([profileId, productIds]) => {
return await shippingProfileServiceTx.removeProducts(