feat(tax): add endpoints to create tax regions and tax rates (#6533)

**What**
Adds:
- POST /admin/tax-regions
- POST /admin/tax-rates
- GET /admin/tax-rates
- `createTaxRegionsWorkflow`
- `createTaxRatesWorkflow`
This commit is contained in:
Sebastian Rindom
2024-02-29 10:26:21 +00:00
committed by GitHub
parent e076590ff2
commit 2407b443f1
20 changed files with 590 additions and 5 deletions
+1
View File
@@ -7,5 +7,6 @@ export * from "./invite"
export * from "./promotion"
export * from "./region"
export * from "./user"
export * from "./tax"
export * from "./api-key"
export * from "./store"
+2
View File
@@ -0,0 +1,2 @@
export * from "./steps"
export * from "./workflows"
@@ -0,0 +1,31 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { CreateTaxRateDTO, ITaxModuleService } from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createTaxRatesStepId = "create-tax-rates"
export const createTaxRatesStep = createStep(
createTaxRatesStepId,
async (data: CreateTaxRateDTO[], { container }) => {
const service = container.resolve<ITaxModuleService>(
ModuleRegistrationName.TAX
)
const created = await service.create(data)
return new StepResponse(
created,
created.map((rate) => rate.id)
)
},
async (createdIds, { container }) => {
if (!createdIds?.length) {
return
}
const service = container.resolve<ITaxModuleService>(
ModuleRegistrationName.TAX
)
await service.delete(createdIds)
}
)
@@ -0,0 +1,31 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { CreateTaxRegionDTO, ITaxModuleService } from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createTaxRegionsStepId = "create-tax-regions"
export const createTaxRegionsStep = createStep(
createTaxRegionsStepId,
async (data: CreateTaxRegionDTO[], { container }) => {
const service = container.resolve<ITaxModuleService>(
ModuleRegistrationName.TAX
)
const created = await service.createTaxRegions(data)
return new StepResponse(
created,
created.map((region) => region.id)
)
},
async (createdIds, { container }) => {
if (!createdIds?.length) {
return
}
const service = container.resolve<ITaxModuleService>(
ModuleRegistrationName.TAX
)
await service.delete(createdIds)
}
)
@@ -0,0 +1,2 @@
export * from "./create-tax-regions"
export * from "./create-tax-rates"
@@ -0,0 +1,13 @@
import { CreateTaxRateDTO, TaxRateDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { createTaxRatesStep } from "../steps"
type WorkflowInput = CreateTaxRateDTO[]
export const createTaxRatesWorkflowId = "create-tax-rates"
export const createTaxRatesWorkflow = createWorkflow(
createTaxRatesWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<TaxRateDTO[]> => {
return createTaxRatesStep(input)
}
)
@@ -0,0 +1,13 @@
import { CreateTaxRegionDTO, TaxRegionDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { createTaxRegionsStep } from "../steps"
type WorkflowInput = CreateTaxRegionDTO[]
export const createTaxRegionsWorkflowId = "create-tax-regions"
export const createTaxRegionsWorkflow = createWorkflow(
createTaxRegionsWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<TaxRegionDTO[]> => {
return createTaxRegionsStep(input)
}
)
@@ -0,0 +1,2 @@
export * from "./create-tax-regions"
export * from "./create-tax-rates"