diff --git a/packages/core/database/src/__tests__/repository.test.ts b/packages/core/database/src/__tests__/repository.test.ts index df513a520..b6a3652ce 100644 --- a/packages/core/database/src/__tests__/repository.test.ts +++ b/packages/core/database/src/__tests__/repository.test.ts @@ -119,6 +119,7 @@ describe('repository.find', () => { const tags = await Tag.repository.create({ values: [{ name: 't1' }, { name: 't2' }], }); + await User.repository.createMany({ records: [ { @@ -188,6 +189,39 @@ describe('repository.find', () => { await db.close(); }); + it('should find with filter', async () => { + const users = await User.repository.find({ + filter: { + name: 'user1', + }, + }); + + expect(users.length).toBe(1); + }); + + it('should find with where', async () => { + const users = await User.repository.find({ + where: { + name: 'user1', + }, + }); + + expect(users.length).toBe(1); + }); + + it('should find with filter and where', async () => { + const users = await User.repository.find({ + filter: { + name: 'user1', + }, + where: { + name: 'user2', + }, + }); + + expect(users.length).toBe(0); + }); + it('should appends with belongs to association', async () => { const posts = await Post.repository.find({ appends: ['user'], diff --git a/packages/core/database/src/repository.ts b/packages/core/database/src/repository.ts index 5bfc4272a..e67ceef4d 100644 --- a/packages/core/database/src/repository.ts +++ b/packages/core/database/src/repository.ts @@ -3,16 +3,16 @@ import lodash from 'lodash'; import { Association, BulkCreateOptions, - ModelStatic, - Op, - Sequelize, - FindAndCountOptions as SequelizeAndCountOptions, CountOptions as SequelizeCountOptions, CreateOptions as SequelizeCreateOptions, DestroyOptions as SequelizeDestroyOptions, + FindAndCountOptions as SequelizeAndCountOptions, FindOptions as SequelizeFindOptions, - UpdateOptions as SequelizeUpdateOptions, + ModelStatic, + Op, + Sequelize, Transactionable, + UpdateOptions as SequelizeUpdateOptions, WhereOperators, } from 'sequelize'; import { Collection } from './collection'; @@ -778,6 +778,13 @@ export class Repository