diff --git a/apps/api/src/app/account/account.controller.ts b/apps/api/src/app/account/account.controller.ts index 873bdc1ed..424d375be 100644 --- a/apps/api/src/app/account/account.controller.ts +++ b/apps/api/src/app/account/account.controller.ts @@ -170,12 +170,27 @@ export class AccountController { ); } + const currentAccountIds = ( + await this.accountService.getAccounts(this.request.user.id) + ).map((account) => account.id); + + if ( + ![accountIdFrom, accountIdTo].every((id) => + currentAccountIds.includes(id) + ) + ) { + throw new HttpException( + getReasonPhrase(StatusCodes.NOT_FOUND), + StatusCodes.NOT_FOUND + ); + } + const today = resetHours(new Date()); const userCurrency = this.request.user.Settings.settings.baseCurrency; await this.accountService.updateAccountBalance({ accountId: accountIdFrom, - amount: balance, + amount: -balance, currency: userCurrency, date: today, userId: this.request.user.id