From 381d2ebf89e36fad475173e9ad01ef7a07e87da6 Mon Sep 17 00:00:00 2001 From: Meli Date: Wed, 17 Jul 2024 11:06:59 +0200 Subject: [PATCH] fix: id filtering crash for ObjectIDs in convertFilter util --- src/utils/converters.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/converters.ts b/src/utils/converters.ts index de6a3a0..3863341 100644 --- a/src/utils/converters.ts +++ b/src/utils/converters.ts @@ -34,6 +34,8 @@ export const convertFilter = (modelFields: DMMF.Model['fields'], filterObject?: if (!filterObject) return {}; const uuidRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-[5|4|3|2|1][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i; + const objectIdRegex = /^[0-9a-fA-F]{24}$/; + const { filters = {} } = filterObject; return Object.entries(filters).reduce((where, [name, filter]) => { if (['boolean', 'number', 'float', 'object', 'array'].includes(filter.property.type())) { @@ -48,7 +50,9 @@ export const convertFilter = (modelFields: DMMF.Model['fields'], filterObject?: } } else if ((filter.property as Property).isEnum()) { where[name] = { equals: filter.value }; - } else if (filter.property.type() === 'string' && uuidRegex.test(filter.value.toString())) { + } else if ( + filter.property.type() === 'string' + && (uuidRegex.test(filter.value.toString()) || objectIdRegex.test(filter.value.toString()))) { where[name] = { equals: filter.value }; } else if (filter.property.type() === 'reference' && (filter.property as Property).foreignColumnName()) { where[(filter.property as Property).foreignColumnName() as string] = convertParam(