Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl committed Mar 28, 2024
1 parent ed06478 commit 06c38d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ISalesChannelModuleService } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import { MedusaError, arrayDifference } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
Expand All @@ -21,19 +21,17 @@ export const validateSalesChannelsExistStep = createStep(
{ select: ["id"] }
)

const scIdsInDb = new Set(salesChannels.map((v) => v.id))
const salesChannelIds = salesChannels.map((v) => v.id)

const notFound = new Set(
[...data.sales_channel_ids].filter((x) => !scIdsInDb.has(x))
)
const notFound = arrayDifference(data.sales_channel_ids, salesChannelIds)

if (notFound.size) {
if (notFound.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Sales channels with IDs ${[...notFound].join(", ")} do not exist`
`Sales channels with IDs ${notFound.join(", ")} do not exist`
)
}

return new StepResponse(Array.from(salesChannels.map((v) => v.id)))
return new StepResponse(salesChannelIds)
}
)
10 changes: 6 additions & 4 deletions packages/medusa/src/api-v2/admin/api-keys/[id]/revoke/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { revokeApiKeysWorkflow } from "@medusajs/core-flows"
import { RevokeApiKeyDTO } from "@medusajs/types"
import { remoteQueryObjectFromString } from "@medusajs/utils"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../../../types/routing"
import { defaultAdminApiKeyFields } from "../../query-config"

export const POST = async (
req: AuthenticatedMedusaRequest,
Expand All @@ -26,14 +28,14 @@ export const POST = async (
throw errors[0].error
}

const remoteQuery = req.scope.resolve("remoteQuery")
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)

const queryObject = remoteQueryObjectFromString({
entryPoint: "api_key",
variables: {
id: req.params.id,
},
fields: defaultAdminApiKeyFields,
fields: req.remoteQueryConfig.fields,
})

const [apiKey] = await remoteQuery(queryObject)
Expand Down
11 changes: 7 additions & 4 deletions packages/medusa/src/api-v2/admin/api-keys/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import {
} from "../../../../types/routing"

import { UpdateApiKeyDTO } from "@medusajs/types"
import { remoteQueryObjectFromString } from "@medusajs/utils"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { defaultAdminApiKeyFields } from "../query-config"

export const GET = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
) => {
const remoteQuery = req.scope.resolve("remoteQuery")
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)

const variables = { id: req.params.id }

Expand Down Expand Up @@ -46,14 +49,14 @@ export const POST = async (
throw errors[0].error
}

const remoteQuery = req.scope.resolve("remoteQuery")
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)

const queryObject = remoteQueryObjectFromString({
entryPoint: "api_key",
variables: {
id: req.params.id,
},
fields: defaultAdminApiKeyFields,
fields: req.remoteQueryConfig.fields,
})

const [apiKey] = await remoteQuery(queryObject)
Expand Down

0 comments on commit 06c38d0

Please sign in to comment.