From d57cb15e3688add55b41be50a9adfcbeda6ad6c9 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Wed, 5 Aug 2026 17:34:56 +0200 Subject: [PATCH] Remove redundant balance attribute from account --- apps/api/src/app/account/account.service.ts | 16 +++++++++------- apps/api/src/app/export/export.service.ts | 4 +--- libs/common/src/lib/dtos/create-account.dto.ts | 7 ++++++- test/import/not-ok/invalid-platform.json | 1 - test/import/ok/500-activities.json | 1 - test/import/ok/derived-currency.json | 1 - test/import/ok/sample.json | 1 - 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/apps/api/src/app/account/account.service.ts b/apps/api/src/app/account/account.service.ts index afe590b8e..4663e387b 100644 --- a/apps/api/src/app/account/account.service.ts +++ b/apps/api/src/app/account/account.service.ts @@ -167,7 +167,7 @@ export class AccountService { tagIds, userId }: { - balance: number; + balance?: number; data: Prisma.AccountCreateInput; tagIds?: string[]; userId: string; @@ -189,12 +189,14 @@ export class AccountService { } }); - await this.accountBalanceService.createOrUpdateAccountBalance({ - balance, - userId, - accountId: account.id, - date: format(new Date(), DATE_FORMAT) - }); + if (balance !== undefined) { + await this.accountBalanceService.createOrUpdateAccountBalance({ + balance, + userId, + accountId: account.id, + date: format(new Date(), DATE_FORMAT) + }); + } this.eventEmitter.emit( PortfolioChangedEvent.getName(), diff --git a/apps/api/src/app/export/export.service.ts b/apps/api/src/app/export/export.service.ts index 02ccb46b3..35db20993 100644 --- a/apps/api/src/app/export/export.service.ts +++ b/apps/api/src/app/export/export.service.ts @@ -102,7 +102,6 @@ export class ExportService { }) .map( ({ - balance, balances, comment, currency, @@ -111,13 +110,12 @@ export class ExportService { platform, platformId, tags - }) => { + }): ExportResponse['accounts'][number] => { if (platformId) { platformsMap[platformId] = platform; } return { - balance, balances: balances.map(({ date, value }) => { return { date: date.toISOString(), value }; }), diff --git a/libs/common/src/lib/dtos/create-account.dto.ts b/libs/common/src/lib/dtos/create-account.dto.ts index cae8293ee..d9e54e305 100644 --- a/libs/common/src/lib/dtos/create-account.dto.ts +++ b/libs/common/src/lib/dtos/create-account.dto.ts @@ -12,8 +12,13 @@ import { import { isString } from 'lodash'; export class CreateAccountDto { + /** + * The initial balance, stored as the account balance of today. + * Optional because the balance is derived from the account balances. + */ @IsNumber() - balance: number; + @IsOptional() + balance?: number; @IsOptional() @IsString() diff --git a/test/import/not-ok/invalid-platform.json b/test/import/not-ok/invalid-platform.json index 69a8e29ca..d280228b8 100644 --- a/test/import/not-ok/invalid-platform.json +++ b/test/import/not-ok/invalid-platform.json @@ -5,7 +5,6 @@ }, "accounts": [ { - "balance": 0, "balances": [], "currency": "USD", "id": "e62be662-a2c8-4cff-8b79-dc0a46576659", diff --git a/test/import/ok/500-activities.json b/test/import/ok/500-activities.json index 03aabca33..3c74d8517 100644 --- a/test/import/ok/500-activities.json +++ b/test/import/ok/500-activities.json @@ -5,7 +5,6 @@ }, "accounts": [ { - "balance": 2000, "currency": "USD", "id": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "name": "My Online Trading Account", diff --git a/test/import/ok/derived-currency.json b/test/import/ok/derived-currency.json index 4b7aa46c3..100ab6739 100644 --- a/test/import/ok/derived-currency.json +++ b/test/import/ok/derived-currency.json @@ -5,7 +5,6 @@ }, "accounts": [ { - "balance": 2000, "currency": "USD", "id": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "name": "My Online Trading Account", diff --git a/test/import/ok/sample.json b/test/import/ok/sample.json index feca8a379..3c75c492b 100644 --- a/test/import/ok/sample.json +++ b/test/import/ok/sample.json @@ -5,7 +5,6 @@ }, "accounts": [ { - "balance": 2000, "balances": [ { "date": "2024-12-31T00:00:00.000Z",