Skip to content

Commit

Permalink
fix!: enable deletion of all entities if options.filters of deleteAll…
Browse files Browse the repository at this point in the history
… is null
  • Loading branch information
Josuto committed Jun 1, 2024
1 parent 9a34d9f commit 6dbbad8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
4 changes: 0 additions & 4 deletions src/mongoose.transactional-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { PartialEntityWithId } from './repository';
import { TransactionalRepository } from './transactional-repository';
import { DomainModel } from './util/domain-model';
import { Entity } from './util/entity';
import { IllegalArgumentException } from './util/exceptions';
import {
DeleteAllOptions,
SaveAllOptions,
Expand Down Expand Up @@ -52,9 +51,6 @@ export abstract class MongooseTransactionalRepository<

/** @inheritdoc */
async deleteAll(options?: DeleteAllOptions): Promise<number> {
if (options?.filters === null) {
throw new IllegalArgumentException('Null filters are disallowed');
}
return await runInTransaction(
async (session: ClientSession) =>
(await this.entityModel.deleteMany(options?.filters, { session }))
Expand Down
9 changes: 4 additions & 5 deletions test/repository/book.transactional-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,12 @@ describe('Given an instance of book repository', () => {
});

describe('that includes a null filter', () => {
it('throws an exception', async () => {
await expect(
bookRepository.deleteAll({ filters: null as unknown as object }),
).rejects.toThrow(IllegalArgumentException);
it('deletes all books', async () => {
const deletedBooks = await bookRepository.deleteAll();
expect(deletedBooks).toBe(2);

const storedBooks = await bookRepository.findAll();
expect(storedBooks).toEqual([storedBook, storedPaperBook]);
expect(storedBooks.length).toBe(0);
});
});

Expand Down

0 comments on commit 6dbbad8

Please sign in to comment.