feat: region payment providers management workflows/api (#6864)
This commit is contained in:
@@ -8,8 +8,10 @@ import {
|
||||
} from "@medusajs/core-flows"
|
||||
|
||||
import { UpdateRegionDTO } from "@medusajs/types"
|
||||
import { defaultAdminRegionFields } from "../query-config"
|
||||
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
@@ -22,7 +24,7 @@ export const GET = async (
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "region",
|
||||
variables,
|
||||
fields: defaultAdminRegionFields,
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [region] = await remoteQuery(queryObject)
|
||||
@@ -46,7 +48,19 @@ export const POST = async (
|
||||
throw errors[0].error
|
||||
}
|
||||
|
||||
res.status(200).json({ region: result[0] })
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "region",
|
||||
variables: {
|
||||
filters: { id: req.params.id },
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const regions = await remoteQuery(queryObject)
|
||||
|
||||
res.status(200).json({ region: regions[0] })
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
|
||||
@@ -40,11 +40,23 @@ export const adminRegionRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/regions",
|
||||
middlewares: [transformBody(AdminPostRegionsReq)],
|
||||
middlewares: [
|
||||
transformQuery(
|
||||
AdminGetRegionsRegionParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
transformBody(AdminPostRegionsReq),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/regions/:id",
|
||||
middlewares: [transformBody(AdminPostRegionsRegionReq)],
|
||||
middlewares: [
|
||||
transformQuery(
|
||||
AdminGetRegionsRegionParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
transformBody(AdminPostRegionsRegionReq),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
export const defaultAdminRegionRelations = ["countries"]
|
||||
export const allowedAdminRegionRelations = ["countries"]
|
||||
export const defaultAdminRegionFields = [
|
||||
"id",
|
||||
"name",
|
||||
@@ -16,13 +14,12 @@ export const defaultAdminRegionFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminRegionFields,
|
||||
defaultRelations: defaultAdminRegionRelations,
|
||||
allowedRelations: allowedAdminRegionRelations,
|
||||
defaults: defaultAdminRegionFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
export const listTransformQueryConfig = {
|
||||
defaults: defaultAdminRegionFields,
|
||||
defaultLimit: 20,
|
||||
isList: true,
|
||||
}
|
||||
|
||||
@@ -5,24 +5,24 @@ import {
|
||||
|
||||
import { CreateRegionDTO } from "@medusajs/types"
|
||||
import { createRegionsWorkflow } from "@medusajs/core-flows"
|
||||
import { defaultAdminRegionFields } from "./query-config"
|
||||
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "region",
|
||||
variables: {
|
||||
filters: req.filterableFields,
|
||||
order: req.listConfig.order,
|
||||
skip: req.listConfig.skip,
|
||||
take: req.listConfig.take,
|
||||
...req.remoteQueryConfig.pagination,
|
||||
},
|
||||
fields: defaultAdminRegionFields,
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const { rows: regions, metadata } = await remoteQuery(queryObject)
|
||||
@@ -46,7 +46,7 @@ export const POST = async (
|
||||
]
|
||||
|
||||
const { result, errors } = await createRegionsWorkflow(req.scope).run({
|
||||
input: { regionsData: input },
|
||||
input: { regions: input },
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
@@ -54,5 +54,17 @@ export const POST = async (
|
||||
throw errors[0].error
|
||||
}
|
||||
|
||||
res.status(200).json({ region: result[0] })
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "region",
|
||||
variables: {
|
||||
filters: { id: result[0].id },
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const regions = await remoteQuery(queryObject)
|
||||
|
||||
res.status(200).json({ region: regions[0] })
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { FindParams, extendedFindParamsMixin } from "../../../types/common"
|
||||
import { extendedFindParamsMixin, FindParams } from "../../../types/common"
|
||||
import { OperatorMapValidator } from "../../../types/validators/operator-map"
|
||||
|
||||
export class AdminGetRegionsRegionParams extends FindParams {}
|
||||
@@ -90,6 +90,11 @@ export class AdminPostRegionsReq {
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, unknown>
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
payment_providers?: string[]
|
||||
}
|
||||
|
||||
export class AdminPostRegionsRegionReq {
|
||||
@@ -108,4 +113,9 @@ export class AdminPostRegionsRegionReq {
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, unknown>
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
payment_providers?: string[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user