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:
Oli Juhl
2024-03-05 09:40:25 +00:00
committed by GitHub
parent 82db53c99e
commit 7d69e6068e
14 changed files with 371 additions and 43 deletions
@@ -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: [],
},
]