forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tax): v2 api tax rates and regions deletes (medusajs#6541)
- Loading branch information
Showing
11 changed files
with
229 additions
and
2 deletions.
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
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,28 @@ | ||
import { ModuleRegistrationName } from "@medusajs/modules-sdk" | ||
import { ITaxModuleService } from "@medusajs/types" | ||
import { StepResponse, createStep } from "@medusajs/workflows-sdk" | ||
|
||
export const deleteTaxRatesStepId = "delete-tax-rates" | ||
export const deleteTaxRatesStep = createStep( | ||
deleteTaxRatesStepId, | ||
async (ids: string[], { container }) => { | ||
const service = container.resolve<ITaxModuleService>( | ||
ModuleRegistrationName.TAX | ||
) | ||
|
||
await service.softDelete(ids) | ||
|
||
return new StepResponse(void 0, ids) | ||
}, | ||
async (prevIds, { container }) => { | ||
if (!prevIds?.length) { | ||
return | ||
} | ||
|
||
const service = container.resolve<ITaxModuleService>( | ||
ModuleRegistrationName.TAX | ||
) | ||
|
||
await service.restore(prevIds) | ||
} | ||
) |
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,28 @@ | ||
import { ModuleRegistrationName } from "@medusajs/modules-sdk" | ||
import { ITaxModuleService } from "@medusajs/types" | ||
import { StepResponse, createStep } from "@medusajs/workflows-sdk" | ||
|
||
export const deleteTaxRegionsStepId = "delete-tax-regions" | ||
export const deleteTaxRegionsStep = createStep( | ||
deleteTaxRegionsStepId, | ||
async (ids: string[], { container }) => { | ||
const service = container.resolve<ITaxModuleService>( | ||
ModuleRegistrationName.TAX | ||
) | ||
|
||
await service.softDeleteTaxRegions(ids) | ||
|
||
return new StepResponse(void 0, ids) | ||
}, | ||
async (prevIds, { container }) => { | ||
if (!prevIds?.length) { | ||
return | ||
} | ||
|
||
const service = container.resolve<ITaxModuleService>( | ||
ModuleRegistrationName.TAX | ||
) | ||
|
||
await service.restoreTaxRegions(prevIds) | ||
} | ||
) |
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,3 +1,5 @@ | ||
export * from "./create-tax-regions" | ||
export * from "./delete-tax-regions" | ||
export * from "./create-tax-rates" | ||
export * from "./update-tax-rates" | ||
export * from "./delete-tax-rates" |
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,12 @@ | ||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk" | ||
import { deleteTaxRatesStep } from "../steps" | ||
|
||
type WorkflowInput = { ids: string[] } | ||
|
||
export const deleteTaxRatesWorkflowId = "delete-tax-rates" | ||
export const deleteTaxRatesWorkflow = createWorkflow( | ||
deleteTaxRatesWorkflowId, | ||
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => { | ||
return deleteTaxRatesStep(input.ids) | ||
} | ||
) |
12 changes: 12 additions & 0 deletions
12
packages/core-flows/src/tax/workflows/delete-tax-regions.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,12 @@ | ||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk" | ||
import { deleteTaxRegionsStep } from "../steps" | ||
|
||
type WorkflowInput = { ids: string[] } | ||
|
||
export const deleteTaxRegionsWorkflowId = "delete-tax-regions" | ||
export const deleteTaxRegionsWorkflow = createWorkflow( | ||
deleteTaxRegionsWorkflowId, | ||
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => { | ||
return deleteTaxRegionsStep(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,3 +1,5 @@ | ||
export * from "./create-tax-regions" | ||
export * from "./delete-tax-regions" | ||
export * from "./create-tax-rates" | ||
export * from "./update-tax-rates" | ||
export * from "./delete-tax-rates" |
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
27 changes: 27 additions & 0 deletions
27
packages/medusa/src/api-v2/admin/tax-regions/[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,27 @@ | ||
import { deleteTaxRegionsWorkflow } from "@medusajs/core-flows" | ||
import { | ||
AuthenticatedMedusaRequest, | ||
MedusaResponse, | ||
} from "../../../../types/routing" | ||
|
||
export const DELETE = async ( | ||
req: AuthenticatedMedusaRequest, | ||
res: MedusaResponse | ||
) => { | ||
const id = req.params.id | ||
|
||
const { errors } = await deleteTaxRegionsWorkflow(req.scope).run({ | ||
input: { ids: [id] }, | ||
throwOnError: false, | ||
}) | ||
|
||
if (Array.isArray(errors) && errors[0]) { | ||
throw errors[0].error | ||
} | ||
|
||
res.status(200).json({ | ||
id, | ||
object: "tax_region", | ||
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
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