Skip to content

Commit b7e5558

Browse files
committed
fix: contains filter not working if value is single
1 parent 0a734e2 commit b7e5558

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/utils/filter/getFilter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ const buildMongoFilter = (filter: any, fields: any[]): any => {
171171
}
172172
case 'contains': {
173173
if (MULTISELECT_TYPES.includes(field.type)) {
174-
return { [fieldName]: { $all: value } };
174+
console.log(value);
175+
if (Array.isArray(value)) {
176+
return { [fieldName]: { $all: value } };
177+
} else {
178+
return { [fieldName]: { $all: [value] } };
179+
}
175180
} else {
176181
return { [fieldName]: { $regex: value, $options: 'i' } };
177182
}

src/utils/schema/resolvers/Query/getFilter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ const buildMongoFilter = (
323323
}
324324
case 'contains': {
325325
if (MULTISELECT_TYPES.includes(type)) {
326-
return { [fieldName]: { $all: value } };
326+
if (Array.isArray(value)) {
327+
return { [fieldName]: { $all: value } };
328+
} else {
329+
return { [fieldName]: { $all: [value] } };
330+
}
327331
} else {
328332
return { [fieldName]: { $regex: value, $options: 'i' } };
329333
}

0 commit comments

Comments
 (0)