Skip to content

Commit

Permalink
fix: nin operator for resource question nested id
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus-relief committed Jun 3, 2024
1 parent 80f04bd commit c842b72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/schema/query/recordsAggregation.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ export default {
[`data.${fieldName}.data.id`]: {
$toString: `$data.${fieldName}._id`,
},
[`data.${fieldName}.data.__ID__`]: {
$toString: `$data.${fieldName}._id`,
},
[`data.${fieldName}.data._id`]: `$data.${fieldName}._id`,
});
} else if (!selectableField.includes('By')) {
Expand Down
15 changes: 12 additions & 3 deletions src/utils/schema/resolvers/Query/getFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,22 @@ const buildMongoFilter = (
}

// Special filter on id, to be used in context filters
if (filter.field === '__ID__') {
if (filter.field.endsWith('__ID__')) {
const toMatch = filter.field.replace('__ID__', '_id');
switch (filter.operator) {
case 'eq':
return { _id: new Types.ObjectId(filter.value) };
return { [toMatch]: new Types.ObjectId(filter.value) };
case 'neq':
return { _id: { $ne: new Types.ObjectId(filter.value) } };
return { [toMatch]: { $ne: new Types.ObjectId(filter.value) } };
default:
case 'in':
return {
[toMatch]: { $in: filter.value.map((x) => new Types.ObjectId(x)) },
};
case 'nin':
return {
[toMatch]: { $nin: filter.value.map((x) => new Types.ObjectId(x)) },
};
return {};
}
}
Expand Down

0 comments on commit c842b72

Please sign in to comment.