Browse Source

Remove redundant balance attribute from account

pull/7546/head
Thomas Kaul 3 weeks ago
parent
commit
d57cb15e36
  1. 4
      apps/api/src/app/account/account.service.ts
  2. 4
      apps/api/src/app/export/export.service.ts
  3. 7
      libs/common/src/lib/dtos/create-account.dto.ts
  4. 1
      test/import/not-ok/invalid-platform.json
  5. 1
      test/import/ok/500-activities.json
  6. 1
      test/import/ok/derived-currency.json
  7. 1
      test/import/ok/sample.json

4
apps/api/src/app/account/account.service.ts

@ -167,7 +167,7 @@ export class AccountService {
tagIds, tagIds,
userId userId
}: { }: {
balance: number; balance?: number;
data: Prisma.AccountCreateInput; data: Prisma.AccountCreateInput;
tagIds?: string[]; tagIds?: string[];
userId: string; userId: string;
@ -189,12 +189,14 @@ export class AccountService {
} }
}); });
if (balance !== undefined) {
await this.accountBalanceService.createOrUpdateAccountBalance({ await this.accountBalanceService.createOrUpdateAccountBalance({
balance, balance,
userId, userId,
accountId: account.id, accountId: account.id,
date: format(new Date(), DATE_FORMAT) date: format(new Date(), DATE_FORMAT)
}); });
}
this.eventEmitter.emit( this.eventEmitter.emit(
PortfolioChangedEvent.getName(), PortfolioChangedEvent.getName(),

4
apps/api/src/app/export/export.service.ts

@ -102,7 +102,6 @@ export class ExportService {
}) })
.map( .map(
({ ({
balance,
balances, balances,
comment, comment,
currency, currency,
@ -111,13 +110,12 @@ export class ExportService {
platform, platform,
platformId, platformId,
tags tags
}) => { }): ExportResponse['accounts'][number] => {
if (platformId) { if (platformId) {
platformsMap[platformId] = platform; platformsMap[platformId] = platform;
} }
return { return {
balance,
balances: balances.map(({ date, value }) => { balances: balances.map(({ date, value }) => {
return { date: date.toISOString(), value }; return { date: date.toISOString(), value };
}), }),

7
libs/common/src/lib/dtos/create-account.dto.ts

@ -12,8 +12,13 @@ import {
import { isString } from 'lodash'; import { isString } from 'lodash';
export class CreateAccountDto { export class CreateAccountDto {
/**
* The initial balance, stored as the account balance of today.
* Optional because the balance is derived from the account balances.
*/
@IsNumber() @IsNumber()
balance: number; @IsOptional()
balance?: number;
@IsOptional() @IsOptional()
@IsString() @IsString()

1
test/import/not-ok/invalid-platform.json

@ -5,7 +5,6 @@
}, },
"accounts": [ "accounts": [
{ {
"balance": 0,
"balances": [], "balances": [],
"currency": "USD", "currency": "USD",
"id": "e62be662-a2c8-4cff-8b79-dc0a46576659", "id": "e62be662-a2c8-4cff-8b79-dc0a46576659",

1
test/import/ok/500-activities.json

@ -5,7 +5,6 @@
}, },
"accounts": [ "accounts": [
{ {
"balance": 2000,
"currency": "USD", "currency": "USD",
"id": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "id": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0",
"name": "My Online Trading Account", "name": "My Online Trading Account",

1
test/import/ok/derived-currency.json

@ -5,7 +5,6 @@
}, },
"accounts": [ "accounts": [
{ {
"balance": 2000,
"currency": "USD", "currency": "USD",
"id": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "id": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0",
"name": "My Online Trading Account", "name": "My Online Trading Account",

1
test/import/ok/sample.json

@ -5,7 +5,6 @@
}, },
"accounts": [ "accounts": [
{ {
"balance": 2000,
"balances": [ "balances": [
{ {
"date": "2024-12-31T00:00:00.000Z", "date": "2024-12-31T00:00:00.000Z",

Loading…
Cancel
Save