diff --git a/packages/core/database/src/__tests__/repository/find.test.ts b/packages/core/database/src/__tests__/repository/find.test.ts index ee7c30355..816d819b6 100644 --- a/packages/core/database/src/__tests__/repository/find.test.ts +++ b/packages/core/database/src/__tests__/repository/find.test.ts @@ -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'], diff --git a/packages/core/database/src/filter-parser.ts b/packages/core/database/src/filter-parser.ts index 6162a2602..dcb1ea1e4 100644 --- a/packages/core/database/src/filter-parser.ts +++ b/packages/core/database/src/filter-parser.ts @@ -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('.'); diff --git a/packages/core/database/src/options-parser.ts b/packages/core/database/src/options-parser.ts index 0582d6367..96ad6cb6a 100644 --- a/packages/core/database/src/options-parser.ts +++ b/packages/core/database/src/options-parser.ts @@ -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'; diff --git a/packages/core/database/src/repository.ts b/packages/core/database/src/repository.ts index 903e8c6ef..224c22f54 100644 --- a/packages/core/database/src/repository.ts +++ b/packages/core/database/src/repository.ts @@ -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';