From 1e7db9488a69f2ec5e525c3adf8ed0a34aae2696 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Thu, 4 May 2023 20:39:43 +0200 Subject: [PATCH] Only update if amount --- apps/api/src/app/account/account.service.ts | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/api/src/app/account/account.service.ts b/apps/api/src/app/account/account.service.ts index e06ea69fd..c6da815e4 100644 --- a/apps/api/src/app/account/account.service.ts +++ b/apps/api/src/app/account/account.service.ts @@ -185,7 +185,7 @@ export class AccountService { currency: string; date: Date; userId: string; - }): Promise { + }) { const { balance, currency: currencyOfAccount } = await this.account({ id_userId: { userId, @@ -201,16 +201,18 @@ export class AccountService { date ); - return this.prismaService.account.update({ - data: { - balance: new Big(balance).plus(amountInCurrencyOfAccount).toNumber() - }, - where: { - id_userId: { - userId, - id: accountId + if (amountInCurrencyOfAccount) { + await this.prismaService.account.update({ + data: { + balance: new Big(balance).plus(amountInCurrencyOfAccount).toNumber() + }, + where: { + id_userId: { + userId, + id: accountId + } } - } - }); + }); + } } }