Balance by user cannot fail but returns undefined if not found

This commit is contained in:
Ulf Gebhardt 2021-10-02 12:46:38 +02:00
parent a4744dd588
commit 7a424c5e33
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD

View File

@ -4,8 +4,6 @@ import { Balance } from '../entity/Balance'
@EntityRepository(Balance) @EntityRepository(Balance)
export class BalanceRepository extends Repository<Balance> { export class BalanceRepository extends Repository<Balance> {
findByUser(userId: number): Promise<Balance | undefined> { findByUser(userId: number): Promise<Balance | undefined> {
return this.createQueryBuilder('balance') return this.createQueryBuilder('balance').where('balance.userId = :userId', { userId }).getOne()
.where('balance.userId = :userId', { userId })
.getOneOrFail()
} }
} }