Skip to content

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

Feature/rename Account to account in Order database schema (#5052)

Thomas Kaul433f1686e33a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7e6574fb7..9080d7ebe4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Changed
+
+- Renamed `Account` to `account` in the `Order` database schema
+
## 2.175.0 - 2025-06-28
### Added
diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts
index bfb9742bc2..b269dc3fde 100644
--- a/apps/api/src/app/import/import.service.ts
+++ b/apps/api/src/app/import/import.service.ts
@@ -71,14 +71,14 @@ export class ImportService {
]);
const accounts = activities
- .filter(({ Account }) => {
- return !!Account;
+ .filter(({ account }) => {
+ return !!account;
})
- .map(({ Account }) => {
- return Account;
+ .map(({ account }) => {
+ return account;
});
- const Account = this.isUniqueAccount(accounts) ? accounts[0] : undefined;
+ const account = this.isUniqueAccount(accounts) ? accounts[0] : undefined;
return await Promise.all(
Object.entries(dividends).map(async ([dateString, { marketPrice }]) => {
@@ -92,7 +92,7 @@ export class ImportService {
const date = parseDate(dateString);
const isDuplicate = activities.some((activity) => {
return (
- activity.accountId === Account?.id &&
+ activity.accountId === account?.id &&
activity.SymbolProfile.currency === assetProfile.currency &&
activity.SymbolProfile.dataSource === assetProfile.dataSource &&
isSameSecond(activity.date, date) &&
@@ -108,12 +108,12 @@ export class ImportService {
: undefined;
return {
- Account,
+ account,
date,
error,
quantity,
value,
- accountId: Account?.id,
+ accountId: account?.id,
accountUserId: undefined,
comment: undefined,
currency: undefined,
@@ -129,7 +129,7 @@ export class ImportService {
unitPrice: marketPrice,
unitPriceInAssetProfileCurrency: marketPrice,
updatedAt: undefined,
- userId: Account?.userId,
+ userId: account?.userId,
valueInBaseCurrency: value
};
})
diff --git a/apps/api/src/app/order/interfaces/activities.interface.ts b/apps/api/src/app/order/interfaces/activities.interface.ts
index c605c4787a..99dd87fea6 100644
--- a/apps/api/src/app/order/interfaces/activities.interface.ts
+++ b/apps/api/src/app/order/interfaces/activities.interface.ts
@@ -9,7 +9,7 @@ export interface Activities {
}
export interface Activity extends Order {
- Account?: AccountWithPlatform;
+ account?: AccountWithPlatform;
error?: ActivityError;
feeInAssetProfileCurrency: number;
feeInBaseCurrency: number;
diff --git a/apps/api/src/app/order/order.controller.ts b/apps/api/src/app/order/order.controller.ts
index f6cfe7922d..33403e85de 100644
--- a/apps/api/src/app/order/order.controller.ts
+++ b/apps/api/src/app/order/order.controller.ts
@@ -269,7 +269,7 @@ export class OrderController {
data: {
...data,
date,
- Account: {
+ account: {
connect: {
id_userId: { id: accountId, userId: this.request.user.id }
}
diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts
index 35e0150b69..c26d53b8fd 100644
--- a/apps/api/src/app/order/order.service.ts
+++ b/apps/api/src/app/order/order.service.ts
@@ -100,10 +100,10 @@ export class OrderService {
userId: string;
}
): Promise<Order> {
- let Account: Prisma.AccountCreateNestedOneWithoutActivitiesInput;
+ let account: Prisma.AccountCreateNestedOneWithoutActivitiesInput;
if (data.accountId) {
- Account = {
+ account = {
connect: {
id_userId: {
userId: data.userId,
@@ -179,7 +179,7 @@ export class OrderService {
const order = await this.prismaService.order.create({
data: {
...orderData,
- Account,
+ account,
isDraft,
tags: {
connect: tags.map(({ id }) => {
@@ -475,8 +475,8 @@ export class OrderService {
if (withExcludedAccounts === false) {
where.OR = [
- { Account: null },
- { Account: { NOT: { isExcluded: true } } }
+ { account: null },
+ { account: { NOT: { isExcluded: true } } }
];
}
@@ -487,8 +487,7 @@ export class OrderService {
take,
where,
include: {
- // eslint-disable-next-line @typescript-eslint/naming-convention
- Account: {
+ account: {
include: {
platform: true
}
@@ -650,8 +649,8 @@ export class OrderService {
if (['FEE', 'INTEREST', 'ITEM', 'LIABILITY'].includes(data.type)) {
delete data.SymbolProfile.connect;
- if (data.Account?.connect?.id_userId?.id === null) {
- data.Account = { disconnect: true };
+ if (data.account?.connect?.id_userId?.id === null) {
+ data.account = { disconnect: true };
}
} else {
delete data.SymbolProfile.update;
diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts
index fc125656b3..6f788a8326 100644
--- a/apps/api/src/app/portfolio/portfolio.service.ts
+++ b/apps/api/src/app/portfolio/portfolio.service.ts
@@ -1883,7 +1883,7 @@ export class PortfolioService {
const nonExcludedActivities: Activity[] = [];
for (const activity of activities) {
- if (activity.Account?.isExcluded) {
+ if (activity.account?.isExcluded) {
excludedActivities.push(activity);
} else {
nonExcludedActivities.push(activity);
@@ -2190,7 +2190,7 @@ export class PortfolioService {
}
for (const {
- Account,
+ account,
quantity,
SymbolProfile,
type
@@ -2201,27 +2201,27 @@ export class PortfolioService {
(portfolioItemsNow[SymbolProfile.symbol]?.marketPriceInBaseCurrency ??
0);
- if (accounts[Account?.id || UNKNOWN_KEY]?.valueInBaseCurrency) {
- accounts[Account?.id || UNKNOWN_KEY].valueInBaseCurrency +=
+ if (accounts[account?.id || UNKNOWN_KEY]?.valueInBaseCurrency) {
+ accounts[account?.id || UNKNOWN_KEY].valueInBaseCurrency +=
currentValueOfSymbolInBaseCurrency;
} else {
- accounts[Account?.id || UNKNOWN_KEY] = {
+ accounts[account?.id || UNKNOWN_KEY] = {
balance: 0,
- currency: Account?.currency,
+ currency: account?.currency,
name: account.name,
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency
};
}
if (
- platforms[Account?.platformId || UNKNOWN_KEY]?.valueInBaseCurrency
+ platforms[account?.platformId || UNKNOWN_KEY]?.valueInBaseCurrency
) {
- platforms[Account?.platformId || UNKNOWN_KEY].valueInBaseCurrency +=
+ platforms[account?.platformId || UNKNOWN_KEY].valueInBaseCurrency +=
currentValueOfSymbolInBaseCurrency;
} else {
- platforms[Account?.platformId || UNKNOWN_KEY] = {
+ platforms[account?.platformId || UNKNOWN_KEY] = {
balance: 0,
- currency: Account?.currency,
+ currency: account?.currency,
name: account.platform?.name,
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency
};
diff --git a/libs/common/src/lib/types/order-with-account.type.ts b/libs/common/src/lib/types/order-with-account.type.ts
index af88030918..b3ae4a990a 100644
--- a/libs/common/src/lib/types/order-with-account.type.ts
+++ b/libs/common/src/lib/types/order-with-account.type.ts
@@ -3,7 +3,7 @@ import { Order, SymbolProfile, Tag } from '@prisma/client';
import { AccountWithPlatform } from './account-with-platform.type';
export type OrderWithAccount = Order & {
- Account?: AccountWithPlatform;
+ account?: AccountWithPlatform;
SymbolProfile?: SymbolProfile;
tags?: Tag[];
};
diff --git a/libs/ui/src/lib/account-balances/account-balances.component.html b/libs/ui/src/lib/account-balances/account-balances.component.html
index 0cfa4a5da6..caef922ed7 100644
--- a/libs/ui/src/lib/account-balances/account-balances.component.html
+++ b/libs/ui/src/lib/account-balances/account-balances.component.html
@@ -38,7 +38,7 @@
<gf-value
[isCurrency]="true"
[locale]="locale"
- [unit]="element?.Account?.currency"
+ [unit]="element?.account?.currency"
[value]="element?.value"
/>
</div>
diff --git a/libs/ui/src/lib/activities-table/activities-table.component.html b/libs/ui/src/lib/activities-table/activities-table.component.html
index b50e32ca38..59ec6315f3 100644
--- a/libs/ui/src/lib/activities-table/activities-table.component.html
+++ b/libs/ui/src/lib/activities-table/activities-table.component.html
@@ -309,14 +309,14 @@
</th>
<td *matCellDef="let element" class="px-1" mat-cell>
<div class="d-flex">
- @if (element.Account?.platform?.url) {
+ @if (element.account?.platform?.url) {
<gf-entity-logo
class="mr-1"
- [tooltip]="element.Account?.platform?.name"
- [url]="element.Account?.platform?.url"
+ [tooltip]="element.account?.platform?.name"
+ [url]="element.account?.platform?.url"
/>
}
- <span class="d-none d-lg-block">{{ element.Account?.name }}</span>
+ <span class="d-none d-lg-block">{{ element.account?.name }}</span>
</div>
</td>
</ng-container>
@@ -468,7 +468,7 @@
[ngClass]="{
'cursor-pointer':
hasPermissionToOpenDetails &&
- row.Account?.isExcluded !== true &&
+ row.account?.isExcluded !== true &&
row.isDraft === false &&
['BUY', 'DIVIDEND', 'SELL'].includes(row.type)
}"
diff --git a/libs/ui/src/lib/activities-table/activities-table.component.ts b/libs/ui/src/lib/activities-table/activities-table.component.ts
index a013081f4a..140dd9e4ee 100644
--- a/libs/ui/src/lib/activities-table/activities-table.component.ts
+++ b/libs/ui/src/lib/activities-table/activities-table.component.ts
@@ -195,7 +195,7 @@ export class GfActivitiesTableComponent
}
} else if (
this.hasPermissionToOpenDetails &&
- activity.Account?.isExcluded !== true &&
+ activity.account?.isExcluded !== true &&
activity.isDraft === false &&
['BUY', 'DIVIDEND', 'SELL'].includes(activity.type)
) {
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index b5d1c98141..567aeb4d04 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -120,6 +120,7 @@ model MarketData {
}
model Order {
+ account Account? @relation(fields: [accountId, accountUserId], references: [id, userId])
accountId String?
accountUserId String?
comment String?
@@ -137,7 +138,6 @@ model Order {
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], onDelete: Cascade, references: [id])
userId String
- Account Account? @relation(fields: [accountId, accountUserId], references: [id, userId])
SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id])
@@index([accountId])