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

4
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 };
}),

7
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()

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

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

1
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",

1
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",

1
test/import/ok/sample.json

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

Loading…
Cancel
Save