Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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