Browse Source

Feature/rename Platform to platform in Account database schema (#4999)

* Rename Platform to platform in Account database schema

* Update changelog
pull/5008/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
738f7490f6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 6
      apps/api/src/app/account/account.controller.ts
  3. 7
      apps/api/src/app/account/account.service.ts
  4. 4
      apps/api/src/app/export/export.service.ts
  5. 2
      apps/api/src/app/import/import.service.ts
  6. 2
      apps/api/src/app/order/order.service.ts
  7. 27
      apps/api/src/app/portfolio/portfolio.service.ts
  8. 2
      apps/api/src/app/user/user.service.ts
  9. 4
      apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts
  10. 16
      apps/client/src/app/components/accounts-table/accounts-table.component.html
  11. 12
      apps/client/src/app/pages/accounts/transfer-balance/transfer-balance-dialog.html
  12. 6
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html
  13. 2
      libs/common/src/lib/types/account-with-platform.type.ts
  14. 2
      libs/common/src/lib/types/account-with-value.type.ts
  15. 6
      libs/ui/src/lib/activities-table/activities-table.component.html
  16. 6
      libs/ui/src/lib/assistant/assistant.html
  17. 2
      prisma/schema.prisma

1
CHANGELOG.md

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Migrated the `@ghostfolio/ui/value` component to control flow - Migrated the `@ghostfolio/ui/value` component to control flow
- Renamed `Platform` to `platform` in the `Account` database schema
- Refactored the health check endpoint for data enhancers - Refactored the health check endpoint for data enhancers
- Refactored the health check endpoint for data providers - Refactored the health check endpoint for data providers

6
apps/api/src/app/account/account.controller.ts

@ -152,7 +152,7 @@ export class AccountController {
return this.accountService.createAccount( return this.accountService.createAccount(
{ {
...data, ...data,
Platform: { connect: { id: platformId } }, platform: { connect: { id: platformId } },
user: { connect: { id: this.request.user.id } } user: { connect: { id: this.request.user.id } }
}, },
this.request.user.id this.request.user.id
@ -250,7 +250,7 @@ export class AccountController {
{ {
data: { data: {
...data, ...data,
Platform: { connect: { id: platformId } }, platform: { connect: { id: platformId } },
user: { connect: { id: this.request.user.id } } user: { connect: { id: this.request.user.id } }
}, },
where: { where: {
@ -270,7 +270,7 @@ export class AccountController {
{ {
data: { data: {
...data, ...data,
Platform: originalAccount.platformId platform: originalAccount.platformId
? { disconnect: true } ? { disconnect: true }
: undefined, : undefined,
user: { connect: { id: this.request.user.id } } user: { connect: { id: this.request.user.id } }

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

@ -64,7 +64,7 @@ export class AccountService {
(Account & { (Account & {
activities?: Order[]; activities?: Order[];
balances?: AccountBalance[]; balances?: AccountBalance[];
Platform?: Platform; platform?: Platform;
})[] })[]
> { > {
const { include = {}, skip, take, cursor, where, orderBy } = params; const { include = {}, skip, take, cursor, where, orderBy } = params;
@ -140,7 +140,10 @@ export class AccountService {
public async getAccounts(aUserId: string): Promise<Account[]> { public async getAccounts(aUserId: string): Promise<Account[]> {
const accounts = await this.accounts({ const accounts = await this.accounts({
include: { activities: true, Platform: true }, include: {
activities: true,
platform: true
},
orderBy: { name: 'asc' }, orderBy: { name: 'asc' },
where: { userId: aUserId } where: { userId: aUserId }
}); });

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

@ -48,7 +48,7 @@ export class ExportService {
await this.accountService.accounts({ await this.accountService.accounts({
include: { include: {
balances: true, balances: true,
Platform: true platform: true
}, },
orderBy: { orderBy: {
name: 'asc' name: 'asc'
@ -72,7 +72,7 @@ export class ExportService {
id, id,
isExcluded, isExcluded,
name, name,
Platform: platform, platform,
platformId platformId
}) => { }) => {
if (platformId) { if (platformId) {

2
apps/api/src/app/import/import.service.ts

@ -207,7 +207,7 @@ export class ImportService {
) { ) {
accountObject = { accountObject = {
...accountObject, ...accountObject,
Platform: { connect: { id: platformId } } platform: { connect: { id: platformId } }
}; };
} }

2
apps/api/src/app/order/order.service.ts

@ -490,7 +490,7 @@ export class OrderService {
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
Account: { Account: {
include: { include: {
Platform: true platform: true
} }
}, },
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention

27
apps/api/src/app/portfolio/portfolio.service.ts

@ -158,7 +158,10 @@ export class PortfolioService {
const [accounts, details] = await Promise.all([ const [accounts, details] = await Promise.all([
this.accountService.accounts({ this.accountService.accounts({
where, where,
include: { activities: true, Platform: true }, include: {
activities: true,
platform: true
},
orderBy: { name: 'asc' } orderBy: { name: 'asc' }
}), }),
this.getDetails({ this.getDetails({
@ -2107,14 +2110,14 @@ export class PortfolioService {
let currentAccounts: (Account & { let currentAccounts: (Account & {
Order?: Order[]; Order?: Order[];
Platform?: Platform; platform?: Platform;
})[] = []; })[] = [];
if (filters.length === 0) { if (filters.length === 0) {
currentAccounts = await this.accountService.getAccounts(userId); currentAccounts = await this.accountService.getAccounts(userId);
} else if (filters.length === 1 && filters[0].type === 'ACCOUNT') { } else if (filters.length === 1 && filters[0].type === 'ACCOUNT') {
currentAccounts = await this.accountService.accounts({ currentAccounts = await this.accountService.accounts({
include: { Platform: true }, include: { platform: true },
where: { id: filters[0].id } where: { id: filters[0].id }
}); });
} else { } else {
@ -2131,7 +2134,7 @@ export class PortfolioService {
); );
currentAccounts = await this.accountService.accounts({ currentAccounts = await this.accountService.accounts({
include: { Platform: true }, include: { platform: true },
where: { id: { in: accountIds } } where: { id: { in: accountIds } }
}); });
} }
@ -2156,18 +2159,18 @@ export class PortfolioService {
) )
}; };
if (platforms[account.Platform?.id || UNKNOWN_KEY]?.valueInBaseCurrency) { if (platforms[account.platformId || UNKNOWN_KEY]?.valueInBaseCurrency) {
platforms[account.Platform?.id || UNKNOWN_KEY].valueInBaseCurrency += platforms[account.platformId || UNKNOWN_KEY].valueInBaseCurrency +=
this.exchangeRateDataService.toCurrency( this.exchangeRateDataService.toCurrency(
account.balance, account.balance,
account.currency, account.currency,
userCurrency userCurrency
); );
} else { } else {
platforms[account.Platform?.id || UNKNOWN_KEY] = { platforms[account.platformId || UNKNOWN_KEY] = {
balance: account.balance, balance: account.balance,
currency: account.currency, currency: account.currency,
name: account.Platform?.name, name: account.platform?.name,
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
account.balance, account.balance,
account.currency, account.currency,
@ -2201,15 +2204,15 @@ export class PortfolioService {
} }
if ( if (
platforms[Account?.Platform?.id || UNKNOWN_KEY]?.valueInBaseCurrency platforms[Account?.platformId || UNKNOWN_KEY]?.valueInBaseCurrency
) { ) {
platforms[Account?.Platform?.id || UNKNOWN_KEY].valueInBaseCurrency += platforms[Account?.platformId || UNKNOWN_KEY].valueInBaseCurrency +=
currentValueOfSymbolInBaseCurrency; currentValueOfSymbolInBaseCurrency;
} else { } else {
platforms[Account?.Platform?.id || UNKNOWN_KEY] = { platforms[Account?.platformId || UNKNOWN_KEY] = {
balance: 0, balance: 0,
currency: Account?.currency, currency: Account?.currency,
name: account.Platform?.name, name: account.platform?.name,
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency valueInBaseCurrency: currentValueOfSymbolInBaseCurrency
}; };
} }

2
apps/api/src/app/user/user.service.ts

@ -196,7 +196,7 @@ export class UserService {
include: { include: {
Access: true, Access: true,
accounts: { accounts: {
include: { Platform: true } include: { platform: true }
}, },
Analytics: true, Analytics: true,
Settings: true, Settings: true,

4
apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts

@ -174,7 +174,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
balance, balance,
currency, currency,
name, name,
Platform, platform,
transactionCount, transactionCount,
value, value,
valueInBaseCurrency valueInBaseCurrency
@ -189,7 +189,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
} }
this.name = name; this.name = name;
this.platformName = Platform?.name ?? '-'; this.platformName = platform?.name ?? '-';
this.transactionCount = transactionCount; this.transactionCount = transactionCount;
this.valueInBaseCurrency = valueInBaseCurrency; this.valueInBaseCurrency = valueInBaseCurrency;

16
apps/client/src/app/components/accounts-table/accounts-table.component.html

@ -43,11 +43,11 @@
<ng-container i18n>Name</ng-container> <ng-container i18n>Name</ng-container>
</th> </th>
<td *matCellDef="let element" class="px-1" mat-cell> <td *matCellDef="let element" class="px-1" mat-cell>
@if (element.Platform?.url) { @if (element.platform?.url) {
<gf-entity-logo <gf-entity-logo
class="d-inline d-sm-none mr-1" class="d-inline d-sm-none mr-1"
[tooltip]="element.Platform?.name" [tooltip]="element.platform?.name"
[url]="element.Platform.url" [url]="element.platform.url"
/> />
} }
<span>{{ element.name }}</span> <span>{{ element.name }}</span>
@ -81,7 +81,7 @@
*matHeaderCellDef *matHeaderCellDef
class="d-none d-lg-table-cell px-1" class="d-none d-lg-table-cell px-1"
mat-header-cell mat-header-cell
mat-sort-header="Platform.name" mat-sort-header="platform.name"
> >
<ng-container i18n>Platform</ng-container> <ng-container i18n>Platform</ng-container>
</th> </th>
@ -91,14 +91,14 @@
mat-cell mat-cell
> >
<div class="d-flex"> <div class="d-flex">
@if (element.Platform?.url) { @if (element.platform?.url) {
<gf-entity-logo <gf-entity-logo
class="mr-1" class="mr-1"
[tooltip]="element.Platform?.name" [tooltip]="element.platform?.name"
[url]="element.Platform.url" [url]="element.platform.url"
/> />
} }
<span>{{ element.Platform?.name }}</span> <span>{{ element.platform?.name }}</span>
</div> </div>
</td> </td>
<td <td

12
apps/client/src/app/pages/accounts/transfer-balance/transfer-balance-dialog.html

@ -13,11 +13,11 @@
@for (account of accounts; track account) { @for (account of accounts; track account) {
<mat-option [value]="account.id"> <mat-option [value]="account.id">
<div class="d-flex"> <div class="d-flex">
@if (account.Platform?.url) { @if (account.platform?.url) {
<gf-entity-logo <gf-entity-logo
class="mr-1" class="mr-1"
[tooltip]="account.Platform?.name" [tooltip]="account.platform?.name"
[url]="account.Platform?.url" [url]="account.platform?.url"
/> />
} }
<span>{{ account.name }}</span> <span>{{ account.name }}</span>
@ -34,11 +34,11 @@
@for (account of accounts; track account) { @for (account of accounts; track account) {
<mat-option [value]="account.id"> <mat-option [value]="account.id">
<div class="d-flex"> <div class="d-flex">
@if (account.Platform?.url) { @if (account.platform?.url) {
<gf-entity-logo <gf-entity-logo
class="mr-1" class="mr-1"
[tooltip]="account.Platform?.name" [tooltip]="account.platform?.name"
[url]="account.Platform?.url" [url]="account.platform?.url"
/> />
} }
<span>{{ account.name }}</span> <span>{{ account.name }}</span>

6
apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html

@ -93,11 +93,11 @@
@for (account of data.accounts; track account) { @for (account of data.accounts; track account) {
<mat-option [value]="account.id"> <mat-option [value]="account.id">
<div class="d-flex"> <div class="d-flex">
@if (account.Platform?.url) { @if (account.platform?.url) {
<gf-entity-logo <gf-entity-logo
class="mr-1" class="mr-1"
[tooltip]="account.Platform?.name" [tooltip]="account.platform?.name"
[url]="account.Platform?.url" [url]="account.platform?.url"
/> />
} }
<span>{{ account.name }}</span> <span>{{ account.name }}</span>

2
libs/common/src/lib/types/account-with-platform.type.ts

@ -1,3 +1,3 @@
import { Account, Platform } from '@prisma/client'; import { Account, Platform } from '@prisma/client';
export type AccountWithPlatform = Account & { Platform?: Platform }; export type AccountWithPlatform = Account & { platform?: Platform };

2
libs/common/src/lib/types/account-with-value.type.ts

@ -2,7 +2,7 @@ import { Account as AccountModel, Platform } from '@prisma/client';
export type AccountWithValue = AccountModel & { export type AccountWithValue = AccountModel & {
balanceInBaseCurrency: number; balanceInBaseCurrency: number;
Platform?: Platform; platform?: Platform;
transactionCount: number; transactionCount: number;
value: number; value: number;
valueInBaseCurrency: number; valueInBaseCurrency: number;

6
libs/ui/src/lib/activities-table/activities-table.component.html

@ -309,11 +309,11 @@
</th> </th>
<td *matCellDef="let element" class="px-1" mat-cell> <td *matCellDef="let element" class="px-1" mat-cell>
<div class="d-flex"> <div class="d-flex">
@if (element.Account?.Platform?.url) { @if (element.Account?.platform?.url) {
<gf-entity-logo <gf-entity-logo
class="mr-1" class="mr-1"
[tooltip]="element.Account?.Platform?.name" [tooltip]="element.Account?.platform?.name"
[url]="element.Account?.Platform?.url" [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>

6
libs/ui/src/lib/assistant/assistant.html

@ -149,11 +149,11 @@
@for (account of accounts; track account.id) { @for (account of accounts; track account.id) {
<mat-option [value]="account.id"> <mat-option [value]="account.id">
<div class="d-flex"> <div class="d-flex">
@if (account.Platform?.url) { @if (account.platform?.url) {
<gf-entity-logo <gf-entity-logo
class="mr-1" class="mr-1"
[tooltip]="account.Platform?.name" [tooltip]="account.platform?.name"
[url]="account.Platform?.url" [url]="account.platform?.url"
/> />
} }
<span>{{ account.name }}</span> <span>{{ account.name }}</span>

2
prisma/schema.prisma

@ -35,11 +35,11 @@ model Account {
id String @default(uuid()) id String @default(uuid())
isExcluded Boolean @default(false) isExcluded Boolean @default(false)
name String? name String?
platform Platform? @relation(fields: [platformId], references: [id])
platformId String? platformId String?
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
user User @relation(fields: [userId], onDelete: Cascade, references: [id]) user User @relation(fields: [userId], onDelete: Cascade, references: [id])
userId String userId String
Platform Platform? @relation(fields: [platformId], references: [id])
@@id([id, userId]) @@id([id, userId])
@@index([currency]) @@index([currency])

Loading…
Cancel
Save