From 5d9ea4f71825ea34e5b9945e0b7de32089cfdb75 Mon Sep 17 00:00:00 2001 From: Stevche Radevski Date: Thu, 25 Jul 2024 16:54:42 +0200 Subject: [PATCH] fix: Also apply simple type to operator map (#8278) --- packages/medusa/src/api/utils/validators.ts | 41 ++++++++++----------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/medusa/src/api/utils/validators.ts b/packages/medusa/src/api/utils/validators.ts index 11ffe6e271..9aa72771a2 100644 --- a/packages/medusa/src/api/utils/validators.ts +++ b/packages/medusa/src/api/utils/validators.ts @@ -77,30 +77,29 @@ export const createOperatorMap = ( type = z.string() } - let unionType: any = z.union([type, z.array(type)]).optional() - let arrayType: any = z.array(type).optional() let simpleType: any = type.optional() - if (valueParser) { - unionType = z - .preprocess(valueParser, z.union([type, z.array(type)])) - .optional() - arrayType = z.preprocess(valueParser, z.array(type)).optional() simpleType = z.preprocess(valueParser, type).optional() } - return z.object({ - $eq: unionType, - $ne: unionType, - $in: arrayType, - $nin: arrayType, - $like: simpleType, - $ilike: simpleType, - $re: simpleType, - $contains: simpleType, - $gt: simpleType, - $gte: simpleType, - $lt: simpleType, - $lte: simpleType, - }) + const arrayType: any = z.array(type).optional() + const unionType: any = z.union([simpleType, arrayType]).optional() + + return z.union([ + unionType, + z.object({ + $eq: unionType, + $ne: unionType, + $in: arrayType, + $nin: arrayType, + $like: simpleType, + $ilike: simpleType, + $re: simpleType, + $contains: simpleType, + $gt: simpleType, + $gte: simpleType, + $lt: simpleType, + $lte: simpleType, + }), + ]) }