Browse Source

Remove redundant balance attribute from account

pull/7546/head
Thomas Kaul 3 weeks ago
parent
commit
43299b865f
  1. 8
      apps/api/src/app/account/account.service.ts
  2. 2
      libs/common/src/lib/dtos/create-account.dto.ts
  3. 7
      libs/common/src/lib/dtos/update-account.dto.ts

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

@ -25,7 +25,7 @@ import {
} from '@prisma/client';
import { Big } from 'big.js';
import { endOfToday, format } from 'date-fns';
import { groupBy } from 'lodash';
import { groupBy, isNil } from 'lodash';
import { CashDetails } from './interfaces/cash-details.interface';
@ -189,7 +189,7 @@ export class AccountService {
}
});
if (balance !== undefined) {
if (!isNil(balance)) {
await this.accountBalanceService.createOrUpdateAccountBalance({
balance,
userId,
@ -311,7 +311,7 @@ export class AccountService {
userId,
where
}: {
balance: number;
balance?: number;
data: Prisma.AccountUpdateInput;
tagIds?: string[];
userId: string;
@ -336,12 +336,14 @@ export class AccountService {
where
});
if (!isNil(balance)) {
await this.accountBalanceService.createOrUpdateAccountBalance({
balance,
userId,
accountId: account.id,
date: format(new Date(), DATE_FORMAT)
});
}
this.eventEmitter.emit(
PortfolioChangedEvent.getName(),

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

@ -14,7 +14,7 @@ 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.
* Optional because callers may instead supply the full history via `balances`.
*/
@IsNumber()
@IsOptional()

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

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

Loading…
Cancel
Save