fix: empty logic operator filter (#961)
This commit is contained in:
parent
6b6951b279
commit
afa172a9be
@ -163,6 +163,16 @@ describe('repository find', () => {
|
||||
expect(users[1]).toEqual(2);
|
||||
});
|
||||
|
||||
test('find with empty or', async () => {
|
||||
const usersCount = await User.repository.count({
|
||||
filter: {
|
||||
$or: [],
|
||||
},
|
||||
});
|
||||
|
||||
expect(usersCount).toEqual(await User.repository.count());
|
||||
});
|
||||
|
||||
test('find with fields', async () => {
|
||||
let user = await User.repository.findOne({
|
||||
fields: ['name'],
|
||||
|
@ -78,7 +78,6 @@ export default class FilterParser {
|
||||
|
||||
const include = {};
|
||||
const where = {};
|
||||
const filter2 = lodash.cloneDeep(flattenedFilter);
|
||||
|
||||
let skipPrefix = null;
|
||||
const associations = model.associations;
|
||||
@ -91,6 +90,11 @@ export default class FilterParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip empty logic operator value
|
||||
if ((key == '$or' || key == '$and') && Array.isArray(value) && value.length == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
debug('handle filter key "%s: "%s"', key, value);
|
||||
let keys = key.split('.');
|
||||
|
||||
|
@ -70,6 +70,7 @@ export class OptionsParser {
|
||||
if (typeof sort === 'string') {
|
||||
sort = sort.split(',');
|
||||
}
|
||||
|
||||
const orderParams = [];
|
||||
for (const sortKey of sort) {
|
||||
let direction = sortKey.startsWith('-') ? 'DESC' : 'ASC';
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
ModelCtor,
|
||||
Op,
|
||||
Transactionable,
|
||||
UpdateOptions as SequelizeUpdateOptions
|
||||
UpdateOptions as SequelizeUpdateOptions,
|
||||
} from 'sequelize';
|
||||
import { WhereOperators } from 'sequelize/types/lib/model';
|
||||
import { Collection } from './collection';
|
||||
|
Loading…
Reference in New Issue
Block a user