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);
|
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 () => {
|
test('find with fields', async () => {
|
||||||
let user = await User.repository.findOne({
|
let user = await User.repository.findOne({
|
||||||
fields: ['name'],
|
fields: ['name'],
|
||||||
|
@ -78,7 +78,6 @@ export default class FilterParser {
|
|||||||
|
|
||||||
const include = {};
|
const include = {};
|
||||||
const where = {};
|
const where = {};
|
||||||
const filter2 = lodash.cloneDeep(flattenedFilter);
|
|
||||||
|
|
||||||
let skipPrefix = null;
|
let skipPrefix = null;
|
||||||
const associations = model.associations;
|
const associations = model.associations;
|
||||||
@ -91,6 +90,11 @@ export default class FilterParser {
|
|||||||
continue;
|
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);
|
debug('handle filter key "%s: "%s"', key, value);
|
||||||
let keys = key.split('.');
|
let keys = key.split('.');
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ export class OptionsParser {
|
|||||||
if (typeof sort === 'string') {
|
if (typeof sort === 'string') {
|
||||||
sort = sort.split(',');
|
sort = sort.split(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderParams = [];
|
const orderParams = [];
|
||||||
for (const sortKey of sort) {
|
for (const sortKey of sort) {
|
||||||
let direction = sortKey.startsWith('-') ? 'DESC' : 'ASC';
|
let direction = sortKey.startsWith('-') ? 'DESC' : 'ASC';
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
ModelCtor,
|
ModelCtor,
|
||||||
Op,
|
Op,
|
||||||
Transactionable,
|
Transactionable,
|
||||||
UpdateOptions as SequelizeUpdateOptions
|
UpdateOptions as SequelizeUpdateOptions,
|
||||||
} from 'sequelize';
|
} from 'sequelize';
|
||||||
import { WhereOperators } from 'sequelize/types/lib/model';
|
import { WhereOperators } from 'sequelize/types/lib/model';
|
||||||
import { Collection } from './collection';
|
import { Collection } from './collection';
|
||||||
|
Loading…
Reference in New Issue
Block a user