Skip to content

Commit

Permalink
use remote query for retrieve
Browse files Browse the repository at this point in the history
  • Loading branch information
pKorsholm authored and olivermrbl committed Feb 14, 2024
1 parent ab606fd commit 3df3ea8
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/medusa/src/api-v2/admin/invites/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ContainerRegistrationKeys,
MedusaError,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
Expand All @@ -10,11 +11,24 @@ import { ModuleRegistrationName } from "../../../../../../modules-sdk/dist"
// Get invite
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
const { id } = req.params
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)

const moduleService: IUserModuleService = req.scope.resolve(
ModuleRegistrationName.USER
)
const invite = await moduleService.retrieveInvite(id, req.retrieveConfig)
const query = remoteQueryObjectFromString({
entryPoint: "invite",
variables: {
id,
},
fields: req.retrieveConfig.select as string[],
})

const [invite] = await remoteQuery(query)

if (!invite) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Invite with id: ${id} was not found`
)
}

res.status(200).json({ invite })
}
Expand Down

0 comments on commit 3df3ea8

Please sign in to comment.