fix: Ensure passed Id filters get applied on top of maybe link filter (#7182)

This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-05-01 11:25:24 +02:00
1 parent 3bf6e50744
commit d930d88369
5 files changed
+62 -1

No files matched your search

@@ -1,6 +1,7 @@
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
arrayIntersection,
} from "@medusajs/utils"
import { NextFunction } from "express"
import { MedusaRequest } from "../../types/routing"
@@ -37,7 +38,19 @@ export function maybeApplyLinkFilter({
const resources = await remoteQuery(queryObject)
filterableFields.id = resources.map((p) => p[resourceId])
let existingIdFilters = filterableFields.id as string[] | string | undefined
if (existingIdFilters) {
if (typeof existingIdFilters === "string") {
existingIdFilters = [existingIdFilters]
}
filterableFields.id = arrayIntersection(
existingIdFilters,
resources.map((p) => p[resourceId])
)
} else {
filterableFields.id = resources.map((p) => p[resourceId])
}
return next()
}