feat(core-flows, medusa): add update stock location endpoint to api-v2 (#6800)
* initial create * add changeset * redo changes for stock locatino module' * initial update * add changeset * move integration tests * update update method * fix integration tests * Update packages/stock-location-next/src/services/stock-location.ts Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * update service * initial fixes * pr feedback * update types * expand revert clause for update * update versioning --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oli Juhl
Riqwan Thamir
parent
0b23e7efb8
commit
4cf71af07d
@@ -1,2 +1,3 @@
|
||||
export * from "./create-stock-locations"
|
||||
export * from "./update-stock-locations"
|
||||
export * from "./delete-stock-locations"
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import {
|
||||
FilterableStockLocationProps,
|
||||
IStockLocationServiceNext,
|
||||
UpdateStockLocationNextInput,
|
||||
} from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
convertItemResponseToUpdateRequest,
|
||||
getSelectsAndRelationsFromObjectArray,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { UpdateStockLocationInput } from "@medusajs/types"
|
||||
|
||||
interface StepInput {
|
||||
selector: FilterableStockLocationProps
|
||||
update: UpdateStockLocationInput
|
||||
}
|
||||
|
||||
export const updateStockLocationsStepId = "update-stock-locations-step"
|
||||
export const updateStockLocationsStep = createStep(
|
||||
updateStockLocationsStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
const stockLocationService = container.resolve<IStockLocationServiceNext>(
|
||||
ModuleRegistrationName.STOCK_LOCATION
|
||||
)
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray([
|
||||
input.update,
|
||||
])
|
||||
|
||||
const dataBeforeUpdate = await stockLocationService.list(input.selector, {
|
||||
select: selects,
|
||||
relations,
|
||||
})
|
||||
|
||||
const updatedStockLocations = await stockLocationService.update(
|
||||
input.selector,
|
||||
input.update
|
||||
)
|
||||
|
||||
return new StepResponse(updatedStockLocations, dataBeforeUpdate)
|
||||
},
|
||||
async (revertInput, { container }) => {
|
||||
if (!revertInput?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const stockLocationService = container.resolve<IStockLocationServiceNext>(
|
||||
ModuleRegistrationName.STOCK_LOCATION
|
||||
)
|
||||
|
||||
await stockLocationService.upsert(
|
||||
revertInput.map((item) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
...(item.metadata ? { metadata: item.metadata } : {}),
|
||||
...(item.address ? { address: item.address } : {}),
|
||||
}))
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./create-stock-locations"
|
||||
export * from "./update-stock-locations"
|
||||
export * from "./delete-stock-locations"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
InventoryNext,
|
||||
StockLocationDTO,
|
||||
UpdateStockLocationNextInput,
|
||||
} from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { FilterableStockLocationProps } from "@medusajs/types"
|
||||
import { UpdateStockLocationInput } from "@medusajs/types"
|
||||
import { updateStockLocationsStep } from "../steps"
|
||||
|
||||
interface WorkflowInput {
|
||||
selector: FilterableStockLocationProps
|
||||
update: UpdateStockLocationInput
|
||||
}
|
||||
export const updateStockLocationsWorkflowId = "update-stock-locations-workflow"
|
||||
export const updateStockLocationsWorkflow = createWorkflow(
|
||||
updateStockLocationsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>): WorkflowData<StockLocationDTO[]> => {
|
||||
return updateStockLocationsStep(input)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user