-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types, medusa, core-flows): add delete-stock-location endpoint t…
…o api-v2 (#6801) * initial create * add changeset * redo changes for stock locatino module' * initial delete stock location * add changeset * pr prep * propagate deletion with common step * move integration tests --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
- Loading branch information
Showing
8 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@medusajs/core-flows": patch | ||
"@medusajs/medusa": patch | ||
"@medusajs/types": patch | ||
--- | ||
|
||
feat(types, medusa, core-flows): add delete-stock-location endpoint to api-v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/core-flows/src/stock-location/steps/delete-stock-locations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { StepResponse, createStep } from "@medusajs/workflows-sdk" | ||
|
||
import { ModuleRegistrationName } from "@medusajs/modules-sdk" | ||
|
||
export const deleteStockLocationsStepId = "delete-stock-locations-step" | ||
export const deleteStockLocationsStep = createStep( | ||
deleteStockLocationsStepId, | ||
async (input: string[], { container }) => { | ||
const service = container.resolve(ModuleRegistrationName.STOCK_LOCATION) | ||
|
||
await service.softDelete(input) | ||
|
||
return new StepResponse(void 0, input) | ||
}, | ||
async (deletedLocaitonIds, { container }) => { | ||
if (!deletedLocaitonIds?.length) { | ||
return | ||
} | ||
const service = container.resolve(ModuleRegistrationName.STOCK_LOCATION) | ||
|
||
await service.restore(deletedLocaitonIds) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./create-stock-locations" | ||
export * from "./delete-stock-locations" |
21 changes: 21 additions & 0 deletions
21
packages/core-flows/src/stock-location/workflows/delete-stock-locations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk" | ||
|
||
import { Modules } from "@medusajs/modules-sdk" | ||
import { deleteStockLocationsStep } from "../steps" | ||
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links" | ||
|
||
interface WorkflowInput { | ||
ids: string[] | ||
} | ||
|
||
export const deleteStockLocationsWorkflowId = "delete-stock-locations-workflow" | ||
export const deleteStockLocationsWorkflow = createWorkflow( | ||
deleteStockLocationsWorkflowId, | ||
(input: WorkflowData<WorkflowInput>) => { | ||
deleteStockLocationsStep(input.ids) | ||
|
||
removeRemoteLinkStep({ | ||
[Modules.STOCK_LOCATION]: { stock_location_id: input.ids }, | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./create-stock-locations" | ||
export * from "./delete-stock-locations" |
22 changes: 22 additions & 0 deletions
22
packages/medusa/src/api-v2/admin/stock-locations/[id]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing" | ||
|
||
import { deleteStockLocationsWorkflow } from "@medusajs/core-flows" | ||
|
||
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => { | ||
const { id } = req.params | ||
|
||
const { errors } = await deleteStockLocationsWorkflow(req.scope).run({ | ||
input: { ids: [id] }, | ||
throwOnError: false, | ||
}) | ||
|
||
if (Array.isArray(errors) && errors[0]) { | ||
throw errors[0].error | ||
} | ||
|
||
res.status(200).json({ | ||
id, | ||
object: "stock_location", | ||
deleted: true, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters