fix: array operator query error (#217)
This commit is contained in:
parent
18b4feb104
commit
4e9baf3957
@ -152,6 +152,21 @@ describe('array field operator', function () {
|
||||
expect(filter2[0].get('name')).toEqual(t2.get('name'));
|
||||
});
|
||||
|
||||
test('$anyOf with $and', async () => {
|
||||
const filter3 = await Test.repository.find({
|
||||
filter: {
|
||||
$and: [
|
||||
{
|
||||
'selected.$anyOf': ['aa'],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(filter3.length).toEqual(1);
|
||||
expect(filter3[0].get('name')).toEqual(t2.get('name'));
|
||||
});
|
||||
|
||||
test('$anyOf', async () => {
|
||||
const filter3 = await Test.repository.find({
|
||||
filter: {
|
||||
|
@ -121,10 +121,12 @@ export default class FilterParser {
|
||||
} else if (typeof opKey === 'function') {
|
||||
skipPrefix = origins.join('.');
|
||||
|
||||
value = opKey(lodash.get(unflatten(originalFiler), skipPrefix), {
|
||||
const queryValue = lodash.get(unflatten(originalFiler), skipPrefix);
|
||||
|
||||
value = opKey(queryValue, {
|
||||
db: this.database,
|
||||
path: skipPrefix,
|
||||
fieldName: skipPrefix.replace(`.${firstKey}`, ''),
|
||||
fieldName: this.getFieldNameFromQueryPath(skipPrefix),
|
||||
model: this.model,
|
||||
});
|
||||
break;
|
||||
@ -220,4 +222,18 @@ export default class FilterParser {
|
||||
debug('where %o, include %o', where, include);
|
||||
return { where, include: toInclude(include) };
|
||||
}
|
||||
|
||||
private getFieldNameFromQueryPath(queryPath: string) {
|
||||
const paths = queryPath.split('.');
|
||||
let fieldName;
|
||||
for (const path of paths) {
|
||||
if (path.startsWith('$') || !lodash.isNaN(parseInt(path))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fieldName = path;
|
||||
}
|
||||
|
||||
return fieldName;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user