feat(core-flows,types,medusa): Add tax region update API (#9634)
* feat(core-flows,types,medusa): Add tax region update API * chore: added specs
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import { deleteTaxRegionsWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
deleteTaxRegionsWorkflow,
|
||||
updateTaxRegionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { HttpTypes, RemoteQueryFunction } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { AdminUpdateTaxRegionType } from "../validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
@@ -27,6 +31,38 @@ export const GET = async (
|
||||
res.status(200).json({ tax_region: taxRegion })
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateTaxRegionType>,
|
||||
res: MedusaResponse<HttpTypes.AdminTaxRegionResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
const query = req.scope.resolve<RemoteQueryFunction>(
|
||||
ContainerRegistrationKeys.QUERY
|
||||
)
|
||||
|
||||
await updateTaxRegionsWorkflow(req.scope).run({
|
||||
input: [
|
||||
{
|
||||
id,
|
||||
...req.validatedBody,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const {
|
||||
data: [tax_region],
|
||||
} = await query.graph(
|
||||
{
|
||||
entity: "tax_region",
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
filters: { id },
|
||||
},
|
||||
{ throwIfKeyNotFound: true }
|
||||
)
|
||||
|
||||
return res.json({ tax_region })
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminTaxRegionDeleteResponse>
|
||||
|
||||
@@ -4,13 +4,14 @@ import {
|
||||
AdminCreateTaxRegion,
|
||||
AdminGetTaxRegionParams,
|
||||
AdminGetTaxRegionsParams,
|
||||
AdminUpdateTaxRegion,
|
||||
} from "./validators"
|
||||
|
||||
import { MiddlewareRoute } from "@medusajs/framework/http"
|
||||
import {
|
||||
validateAndTransformBody,
|
||||
validateAndTransformQuery,
|
||||
} from "@medusajs/framework"
|
||||
import { MiddlewareRoute } from "@medusajs/framework/http"
|
||||
|
||||
export const adminTaxRegionRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
@@ -20,7 +21,18 @@ export const adminTaxRegionRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
validateAndTransformBody(AdminCreateTaxRegion),
|
||||
validateAndTransformQuery(
|
||||
AdminGetTaxRegionsParams,
|
||||
QueryConfig.listTransformQueryConfig
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: "POST",
|
||||
matcher: "/admin/tax-regions/:id",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminUpdateTaxRegion),
|
||||
validateAndTransformQuery(
|
||||
AdminGetTaxRegionsParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
|
||||
@@ -54,3 +54,9 @@ export const AdminCreateTaxRegion = z.object({
|
||||
.optional(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
})
|
||||
|
||||
export type AdminUpdateTaxRegionType = z.infer<typeof AdminUpdateTaxRegion>
|
||||
export const AdminUpdateTaxRegion = z.object({
|
||||
province_code: z.string().nullish(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user