Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/allow account for activity of type item (#1641)

Thomas Kaul2e7f46ad782a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index de5064597d..d8369f702e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
+### Added
+
+- Added support to link a (wealth) item to an account
+
### Changed
- Improved the language localization for German (`de`)
diff --git a/apps/api/src/app/account/account.controller.ts b/apps/api/src/app/account/account.controller.ts
index 2a71042c8c..b85c13ab59 100644
--- a/apps/api/src/app/account/account.controller.ts
+++ b/apps/api/src/app/account/account.controller.ts
@@ -37,8 +37,7 @@ export class AccountController {
private readonly accountService: AccountService,
private readonly impersonationService: ImpersonationService,
private readonly portfolioService: PortfolioService,
- @Inject(REQUEST) private readonly request: RequestWithUser,
- private readonly userService: UserService
+ @Inject(REQUEST) private readonly request: RequestWithUser
) {}
@Delete(':id')
diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts
index c91332785b..077f2227b5 100644
--- a/apps/api/src/app/order/order.service.ts
+++ b/apps/api/src/app/order/order.service.ts
@@ -76,23 +76,21 @@ export class OrderService {
userId: string;
}
): Promise<Order> {
- const defaultAccount = (
- await this.accountService.getAccounts(data.userId)
- ).find((account) => {
- return account.isDefault === true;
- });
+ let Account;
+
+ if (data.accountId) {
+ Account = {
+ connect: {
+ id_userId: {
+ userId: data.userId,
+ id: data.accountId
+ }
+ }
+ };
+ }
const tags = data.tags ?? [];
- let Account = {
- connect: {
- id_userId: {
- userId: data.userId,
- id: data.accountId ?? defaultAccount?.id
- }
- }
- };
-
if (data.type === 'ITEM') {
const assetClass = data.assetClass;
const assetSubClass = data.assetSubClass;
@@ -101,7 +99,6 @@ export class OrderService {
const id = uuidv4();
const name = data.SymbolProfile.connectOrCreate.create.symbol;
- Account = undefined;
data.id = id;
data.SymbolProfile.connectOrCreate.create.assetClass = assetClass;
data.SymbolProfile.connectOrCreate.create.assetSubClass = assetSubClass;
diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts
index bce6de6742..73c24d2b50 100644
--- a/apps/api/src/app/portfolio/portfolio.service.ts
+++ b/apps/api/src/app/portfolio/portfolio.service.ts
@@ -573,7 +573,6 @@ export class PortfolioService {
const cashPositions = await this.getCashPositions({
cashDetails,
userCurrency,
- investment: totalInvestmentInBaseCurrency,
value: filteredValueInBaseCurrency
});
@@ -599,7 +598,6 @@ export class PortfolioService {
const cashPositions = await this.getCashPositions({
cashDetails,
userCurrency,
- investment: totalInvestmentInBaseCurrency,
value: filteredValueInBaseCurrency
});
@@ -1209,12 +1207,10 @@ export class PortfolioService {
private async getCashPositions({
cashDetails,
- investment,
userCurrency,
value
}: {
cashDetails: CashDetails;
- investment: Big;
userCurrency: string;
value: Big;
}) {
@@ -1692,6 +1688,14 @@ export class PortfolioService {
userId: string;
withExcludedAccounts?: boolean;
}) {
+ const ordersOfTypeItem = await this.orderService.getOrders({
+ filters,
+ userCurrency,
+ userId,
+ withExcludedAccounts,
+ types: ['ITEM']
+ });
+
const accounts: PortfolioDetails['accounts'] = {};
let currentAccounts: (Account & {
@@ -1722,10 +1726,18 @@ export class PortfolioService {
});
for (const account of currentAccounts) {
- const ordersByAccount = orders.filter(({ accountId }) => {
+ let ordersByAccount = orders.filter(({ accountId }) => {
return accountId === account.id;
});
+ const ordersOfTypeItemByAccount = ordersOfTypeItem.filter(
+ ({ accountId }) => {
+ return accountId === account.id;
+ }
+ );
+
+ ordersByAccount = ordersByAccount.concat(ordersOfTypeItemByAccount);
+
accounts[account.id] = {
balance: account.balance,
currency: account.currency,
@@ -1745,7 +1757,9 @@ export class PortfolioService {
for (const order of ordersByAccount) {
let currentValueOfSymbolInBaseCurrency =
order.quantity *
- portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ?? 0;
+ (portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ??
+ order.unitPrice ??
+ 0);
let originalValueOfSymbolInBaseCurrency =
this.exchangeRateDataService.toCurrency(
order.quantity * order.unitPrice,
diff --git a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html
index 6262a65d31..e5b215fbc5 100644
--- a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html
+++ b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html
@@ -18,12 +18,14 @@
</mat-select>
</mat-form-field>
</div>
- <div
- [ngClass]="{ 'd-none': !activityForm.controls['accountId'].hasValidator(Validators.required) }"
- >
+ <div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Account</mat-label>
<mat-select formControlName="accountId">
+ <mat-option
+ *ngIf="!activityForm.controls['accountId'].hasValidator(Validators.required)"
+ [value]="null"
+ ></mat-option>
<mat-option *ngFor="let account of data.accounts" [value]="account.id"
>{{ account.name }}</mat-option
>