feat: loosely typed container
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { CreateStoreDTO, IStoreModuleService } from "@medusajs/types"
|
||||
import { CreateStoreDTO, IStoreModuleService, StoreDTO } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStoresWorkflow } from "../../store"
|
||||
|
||||
@@ -16,8 +16,13 @@ export const createDefaultStoreStep = createStep(
|
||||
let shouldDelete = false
|
||||
let [store] = await storeService.list({}, { take: 1 })
|
||||
|
||||
/**
|
||||
* @todo
|
||||
* Seems like we are missing an integration test when the
|
||||
* following conditional as true.
|
||||
*/
|
||||
if (!store) {
|
||||
store = await createStoresWorkflow(container).run({
|
||||
const stores = await createStoresWorkflow(container).run({
|
||||
input: {
|
||||
stores: [
|
||||
{
|
||||
@@ -30,6 +35,12 @@ export const createDefaultStoreStep = createStep(
|
||||
},
|
||||
})
|
||||
|
||||
/**
|
||||
* As per types, the result from "createStoresWorkflow.run" was
|
||||
* an array of "StoreDTO". But at runtime it turns out to be
|
||||
* a "StoreDTO"
|
||||
*/
|
||||
store = stores as unknown as StoreDTO
|
||||
shouldDelete = true
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ export const updateCartPromotionsStep = createStep(
|
||||
: []
|
||||
|
||||
return new StepResponse(null, {
|
||||
// @ts-expect-error
|
||||
createdLinkIds: createdLinks.map((link) => link.id),
|
||||
dismissedLinks: linksToDismiss,
|
||||
})
|
||||
@@ -95,6 +96,7 @@ export const updateCartPromotionsStep = createStep(
|
||||
}
|
||||
|
||||
if (revertData?.createdLinkIds?.length) {
|
||||
// @ts-expect-error
|
||||
await remoteLink.delete(revertData.createdLinkIds)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,20 @@ export const adjustInventoryLevelsStep = createStep(
|
||||
|
||||
const inventoryService = container.resolve(ModuleRegistrationName.INVENTORY)
|
||||
|
||||
await inventoryService.adjustInventory(adjustedLevels)
|
||||
/**
|
||||
* @todo
|
||||
* The method "adjustInventory" was broken, it was receiving the
|
||||
* "inventoryItemId" and "locationId" as snake case, whereas
|
||||
* the expected object needed these properties as camelCase
|
||||
*/
|
||||
await inventoryService.adjustInventory(
|
||||
adjustedLevels.map((level) => {
|
||||
return {
|
||||
inventoryItemId: level.inventory_item_id,
|
||||
locationId: level.location_id,
|
||||
adjustment: level.adjustment,
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ export const attachInventoryItemToVariants = createStep(
|
||||
.filter(({ tag }) => !!tag)
|
||||
.map(({ inventoryItemId, tag }) => ({
|
||||
productService: {
|
||||
variant_id: tag,
|
||||
variant_id: tag!,
|
||||
},
|
||||
inventoryService: {
|
||||
inventory_item_id: inventoryItemId,
|
||||
|
||||
+6
-10
@@ -1,11 +1,5 @@
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
export const validateInventoryItemsForCreateStepId =
|
||||
@@ -25,7 +19,7 @@ export const validateInventoryItemsForCreate = createStep(
|
||||
"variant_id",
|
||||
Modules.INVENTORY,
|
||||
"inventory_item_id"
|
||||
)
|
||||
)!
|
||||
|
||||
const existingItems = await linkService.list(
|
||||
{ variant_id: input.map((i) => i.tag) },
|
||||
@@ -33,10 +27,12 @@ export const validateInventoryItemsForCreate = createStep(
|
||||
)
|
||||
|
||||
if (existingItems.length) {
|
||||
// @ts-expect-error
|
||||
const ids = existingItems.map((i) => i.variant_id).join(", ")
|
||||
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_ALLOWED,
|
||||
"Inventory items already exist for variants with ids: " +
|
||||
existingItems.map((i) => i.variant_id).join(", ")
|
||||
`Inventory items already exist for variants with ids: ${ids}`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,15 @@ export const getVariantPricingLinkStep = createStep(
|
||||
"variant_id",
|
||||
Modules.PRICING,
|
||||
"price_set_id"
|
||||
)
|
||||
)!
|
||||
|
||||
const existingItems = await linkService.list(
|
||||
const existingItems = (await linkService.list(
|
||||
{ variant_id: data.ids },
|
||||
{ select: ["variant_id", "price_set_id"] }
|
||||
)
|
||||
)) as {
|
||||
variant_id: string
|
||||
price_set_id: string
|
||||
}[]
|
||||
|
||||
if (existingItems.length !== data.ids.length) {
|
||||
const missing = arrayDifference(
|
||||
|
||||
@@ -78,16 +78,22 @@ export const updateProductVariantsWorkflow = createWorkflow(
|
||||
}
|
||||
|
||||
if ("product_variants" in data.input) {
|
||||
return data.variantPriceSetLinks.map((link) => {
|
||||
const variant = (data.input as any).product_variants.find(
|
||||
(v) => v.id === link.variant_id
|
||||
)
|
||||
return data.variantPriceSetLinks
|
||||
.map((link) => {
|
||||
if (!("product_variants" in data.input)) {
|
||||
return
|
||||
}
|
||||
|
||||
return {
|
||||
id: link.price_set_id,
|
||||
prices: variant.prices,
|
||||
} as PricingTypes.UpsertPriceSetDTO
|
||||
})
|
||||
const variant = data.input.product_variants.find(
|
||||
(v) => v.id === link.variant_id
|
||||
)!
|
||||
|
||||
return {
|
||||
id: link.price_set_id,
|
||||
prices: variant.prices,
|
||||
} as PricingTypes.UpsertPriceSetDTO
|
||||
})
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { Modules, RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
|
||||
@@ -17,6 +17,6 @@ export const createUsersStep = createStep(
|
||||
return
|
||||
}
|
||||
const service = container.resolve(ModuleRegistrationName.USER)
|
||||
await service.delete(createdUsers)
|
||||
await service.delete(createdUsers.map((user) => user.id))
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user