From 16ca68a57c8811d059faeeb8f266ee78b76c6e73 Mon Sep 17 00:00:00 2001 From: the-sabra Date: Tue, 6 Aug 2024 18:10:18 +0300 Subject: [PATCH] fix: Handle NotFoundException in ReciterService --- src/reciter/reciter.service.spec.ts | 11 ++++------- src/reciter/reciter.service.ts | 12 ++++++------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/reciter/reciter.service.spec.ts b/src/reciter/reciter.service.spec.ts index c9d1a9f..3b89f68 100644 --- a/src/reciter/reciter.service.spec.ts +++ b/src/reciter/reciter.service.spec.ts @@ -199,10 +199,9 @@ describe('ReciterService', () => { it('should throw NotFoundException if tilawa not found', async () => { jest.spyOn(tilawaRepository, 'findOneBy').mockResolvedValueOnce(null); + const result = service.getReciterTilawaId(1); - await expect(service.getReciterTilawaId(1)).rejects.toThrow( - NotFoundException, - ); + expect(result).rejects.toThrow(NotFoundException); }); }); @@ -224,10 +223,8 @@ describe('ReciterService', () => { it('should throw NotFoundException if no tilawas found', async () => { jest.spyOn(tilawaRepository, 'find').mockResolvedValue([]); - - await expect(service.getReciterTilawa(1)).rejects.toThrow( - NotFoundException, - ); + const result = service.getReciterTilawa(1); + await expect(result).rejects.toThrow(NotFoundException); }); }); diff --git a/src/reciter/reciter.service.ts b/src/reciter/reciter.service.ts index 4b1af90..620daa8 100644 --- a/src/reciter/reciter.service.ts +++ b/src/reciter/reciter.service.ts @@ -76,15 +76,15 @@ export class ReciterService { const tilawa = await this.tilawaRepository.find({ where: { reciter_id: reciterId }, }); - - if (!tilawa) throw new NotFoundException('Tilawa not found'); - + if (!tilawa.length) throw new NotFoundException('Tilawa not found'); return tilawa; } - addReciterTilawa(id: number, addTilawaDto: AddTilawaDto) { - const tilawa = this.tilawaRepository.create(addTilawaDto); - tilawa.reciter_id = id; + addReciterTilawa(id: number, addTilawaDto: Omit) { + const tilawa = this.tilawaRepository.create({ + ...addTilawaDto, + reciter_id: id, + }); return this.tilawaRepository.save(tilawa); } }