Skip to content

Commit 16ca68a

Browse files
committed
fix: Handle NotFoundException in ReciterService
1 parent fdf583b commit 16ca68a

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/reciter/reciter.service.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,9 @@ describe('ReciterService', () => {
199199

200200
it('should throw NotFoundException if tilawa not found', async () => {
201201
jest.spyOn(tilawaRepository, 'findOneBy').mockResolvedValueOnce(null);
202+
const result = service.getReciterTilawaId(1);
202203

203-
await expect(service.getReciterTilawaId(1)).rejects.toThrow(
204-
NotFoundException,
205-
);
204+
expect(result).rejects.toThrow(NotFoundException);
206205
});
207206
});
208207

@@ -224,10 +223,8 @@ describe('ReciterService', () => {
224223

225224
it('should throw NotFoundException if no tilawas found', async () => {
226225
jest.spyOn(tilawaRepository, 'find').mockResolvedValue([]);
227-
228-
await expect(service.getReciterTilawa(1)).rejects.toThrow(
229-
NotFoundException,
230-
);
226+
const result = service.getReciterTilawa(1);
227+
await expect(result).rejects.toThrow(NotFoundException);
231228
});
232229
});
233230

src/reciter/reciter.service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ export class ReciterService {
7676
const tilawa = await this.tilawaRepository.find({
7777
where: { reciter_id: reciterId },
7878
});
79-
80-
if (!tilawa) throw new NotFoundException('Tilawa not found');
81-
79+
if (!tilawa.length) throw new NotFoundException('Tilawa not found');
8280
return tilawa;
8381
}
8482

85-
addReciterTilawa(id: number, addTilawaDto: AddTilawaDto) {
86-
const tilawa = this.tilawaRepository.create(addTilawaDto);
87-
tilawa.reciter_id = id;
83+
addReciterTilawa(id: number, addTilawaDto: Omit<AddTilawaDto, 'reciter_id'>) {
84+
const tilawa = this.tilawaRepository.create({
85+
...addTilawaDto,
86+
reciter_id: id,
87+
});
8888
return this.tilawaRepository.save(tilawa);
8989
}
9090
}

0 commit comments

Comments
 (0)