Skip to content

Commit

Permalink
fix: id filtering crash for ObjectIDs in convertFilter util
Browse files Browse the repository at this point in the history
  • Loading branch information
melifetaji committed Jul 17, 2024
1 parent 0cd6a63 commit 381d2eb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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(
Expand Down

0 comments on commit 381d2eb

Please sign in to comment.