feat(tax): v2 api tax rates and regions deletes (#6541)

This commit is contained in:
Sebastian Rindom
2024-02-29 13:06:11 +01:00
committed by GitHub
parent 6279fb3c67
commit c4760dfd5f
11 changed files with 229 additions and 2 deletions
@@ -6,7 +6,10 @@ import {
import { defaultAdminTaxRateFields } from "../query-config"
import { remoteQueryObjectFromString } from "@medusajs/utils"
import { AdminPostTaxRatesTaxRateReq } from "../../../../api/routes/admin/tax-rates"
import { updateTaxRatesWorkflow } from "@medusajs/core-flows"
import {
deleteTaxRatesWorkflow,
updateTaxRatesWorkflow,
} from "@medusajs/core-flows"
export const POST = async (
req: AuthenticatedMedusaRequest<AdminPostTaxRatesTaxRateReq>,
@@ -55,3 +58,25 @@ export const GET = async (
res.status(200).json({ tax_rate: taxRate })
}
export const DELETE = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
) => {
const id = req.params.id
const { errors } = await deleteTaxRatesWorkflow(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_rate",
deleted: true,
})
}
@@ -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,
})
}