chore: pick the default store region (#7369)

* chore: pick the default store region

* chore: fix test

* chore: remove from defaults workflow and move to seeds

* chore: undo payment provider change

* chore: rearrange conditionals
This commit is contained in:
Riqwan Thamir authored and GitHub committed 2024-05-21 12:05:01 +02:00
1 parent 3dbb256ddf
commit 43613f3f58
5 files changed
+69 -22

No files matched your search

@@ -1,5 +1,5 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IRegionModuleService } from "@medusajs/types"
import { IRegionModuleService, IStoreModuleService } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
@@ -11,21 +11,29 @@ export const findOneOrAnyRegionStep = createStep(
ModuleRegistrationName.REGION
)
if (!data.regionId) {
// TODO: Pick up the default store region if none is provided
const regions = await service.list({})
const storeModule = container.resolve<IStoreModuleService>(
ModuleRegistrationName.STORE
)
if (!regions?.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"No regions found"
)
}
if (data.regionId) {
const region = await service.retrieve(data.regionId)
return new StepResponse(regions[0])
return new StepResponse(region)
}
const region = await service.retrieve(data.regionId)
const [store] = await storeModule.list()
if (!store) {
throw new MedusaError(MedusaError.Types.NOT_FOUND, "Store not found")
}
const [region] = await service.list({
id: store.default_region_id,
})
if (!region) {
throw new MedusaError(MedusaError.Types.INVALID_DATA, "No regions found")
}
return new StepResponse(region)
}