feat: Region PaymentProvider link (#6577)
**What** - Introduce link between Region and PaymentProvider - Introduce API endpoint `GET /store/regions/:id/payment-providers` for retrieving providers by region - Add tests for both
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "regions",
|
||||
fields: ["payment_providers.id", "payment_providers.is_enabled"],
|
||||
variables: {
|
||||
id: req.params.id,
|
||||
},
|
||||
})
|
||||
|
||||
const [region] = await remoteQuery(queryObject)
|
||||
|
||||
res.status(200).json({
|
||||
payment_providers: region.payment_providers.filter((pp) => pp.is_enabled),
|
||||
})
|
||||
}
|
||||
@@ -24,4 +24,9 @@ export const storeRegionRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/store/regions/:id/payment-providers",
|
||||
middlewares: [],
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user