Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support unlimited currencies #387

Merged
merged 4 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Changed the navigation to always show the portfolio page
- Migrated the data type of currencies from `enum` to `string` in the database
- Supported unlimited currencies (instead of `CHF`, `EUR`, `GBP` and `USD`)

### Fixed

- Hid the actions from the accounts table in the _Presenter View_
- Hid the actions from the transactions table in the _Presenter View_

### Todo

- Apply data migration (`yarn prisma migrate deploy`)

## 1.55.0 - 20.09.2021

### Changed
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/account/account.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { Injectable } from '@nestjs/common';
import { Account, Currency, Order, Platform, Prisma } from '@prisma/client';
import { Account, Order, Platform, Prisma } from '@prisma/client';

import { CashDetails } from './interfaces/cash-details.interface';

Expand Down Expand Up @@ -95,7 +95,7 @@ export class AccountService {

public async getCashDetails(
aUserId: string,
aCurrency: Currency
aCurrency: string
): Promise<CashDetails> {
let totalCashBalance = 0;

Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/account/create-account.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountType, Currency } from '@prisma/client';
import { AccountType } from '@prisma/client';
import { IsNumber, IsString, ValidateIf } from 'class-validator';

export class CreateAccountDto {
Expand All @@ -9,7 +9,7 @@ export class CreateAccountDto {
balance: number;

@IsString()
currency: Currency;
currency: string;

@IsString()
name: string;
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/account/update-account.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountType, Currency } from '@prisma/client';
import { AccountType } from '@prisma/client';
import { IsNumber, IsString, ValidateIf } from 'class-validator';

export class UpdateAccountDto {
Expand All @@ -9,7 +9,7 @@ export class UpdateAccountDto {
balance: number;

@IsString()
currency: Currency;
currency: string;

@IsString()
id: string;
Expand Down
65 changes: 17 additions & 48 deletions apps/api/src/app/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ConfigurationService } from '@ghostfolio/api/services/configuration.ser
import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { baseCurrency } from '@ghostfolio/common/config';
import { AdminData } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common';
import { Currency } from '@prisma/client';
import { differenceInDays } from 'date-fns';

@Injectable()
Expand All @@ -20,53 +20,22 @@ export class AdminService {

public async get(): Promise<AdminData> {
return {
exchangeRates: [
{
label1: Currency.EUR,
label2: Currency.CHF,
value: await this.exchangeRateDataService.toCurrency(
1,
Currency.EUR,
Currency.CHF
)
},
{
label1: Currency.GBP,
label2: Currency.CHF,
value: await this.exchangeRateDataService.toCurrency(
1,
Currency.GBP,
Currency.CHF
)
},
{
label1: Currency.USD,
label2: Currency.CHF,
value: await this.exchangeRateDataService.toCurrency(
1,
Currency.USD,
Currency.CHF
)
},
{
label1: Currency.USD,
label2: Currency.EUR,
value: await this.exchangeRateDataService.toCurrency(
1,
Currency.USD,
Currency.EUR
)
},
{
label1: Currency.USD,
label2: Currency.GBP,
value: await this.exchangeRateDataService.toCurrency(
1,
Currency.USD,
Currency.GBP
)
}
],
exchangeRates: this.exchangeRateDataService
.getCurrencies()
.filter((currency) => {
return currency !== baseCurrency;
})
.map((currency) => {
return {
label1: baseCurrency,
label2: currency,
value: this.exchangeRateDataService.toCurrency(
1,
baseCurrency,
currency
)
};
}),
lastDataGathering: await this.getLastDataGathering(),
transactionCount: await this.prismaService.order.count(),
userCount: await this.prismaService.user.count(),
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/app/cache/cache.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { DataProviderService } from '@ghostfolio/api/services/data-provider/data
import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service';
import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service';
import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service';
import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { Module } from '@nestjs/common';

import { CacheController } from './cache.controller';

@Module({
imports: [RedisCacheModule],
imports: [ExchangeRateDataModule, RedisCacheModule],
controllers: [CacheController],
providers: [
AlphaVantageService,
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/app/experimental/create-order.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Currency, Type } from '@prisma/client';
import { IsISO8601, IsNumber, IsString, ValidateIf } from 'class-validator';
import { Type } from '@prisma/client';
import { IsISO8601, IsNumber, IsString } from 'class-validator';

export class CreateOrderDto {
@IsString()
currency: Currency;
currency: string;

@IsISO8601()
date: string;
Expand Down
4 changes: 1 addition & 3 deletions apps/api/src/app/experimental/interfaces/data.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Currency } from '@prisma/client';

export interface Data {
currency: Currency;
currency: string;
value: number;
}
3 changes: 1 addition & 2 deletions apps/api/src/app/export/export.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CacheService } from '@ghostfolio/api/app/cache/cache.service';
import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module';
import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module';
import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering.module';
Expand All @@ -18,6 +17,6 @@ import { ExportService } from './export.service';
RedisCacheModule
],
controllers: [ExportController],
providers: [CacheService, ExportService]
providers: [ExportService]
})
export class ExportModule {}
2 changes: 2 additions & 0 deletions apps/api/src/app/info/info.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DataProviderService } from '@ghostfolio/api/services/data-provider/data
import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service';
import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service';
import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service';
import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
Expand All @@ -14,6 +15,7 @@ import { InfoService } from './info.service';

@Module({
imports: [
ExchangeRateDataModule,
JwtModule.register({
secret: process.env.JWT_SECRET_KEY,
signOptions: { expiresIn: '30 days' }
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/app/info/info.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service';
import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { InfoItem } from '@ghostfolio/common/interfaces';
import { Subscription } from '@ghostfolio/common/interfaces/subscription.interface';
import { permissions } from '@ghostfolio/common/permissions';
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { Currency } from '@prisma/client';
import * as bent from 'bent';
import { subDays } from 'date-fns';

Expand All @@ -16,6 +16,7 @@ export class InfoService {

public constructor(
private readonly configurationService: ConfigurationService,
private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly dataGatheringService: DataGatheringService,
private readonly jwtService: JwtService,
private readonly prismaService: PrismaService
Expand Down Expand Up @@ -56,7 +57,7 @@ export class InfoService {
...info,
globalPermissions,
platforms,
currencies: Object.values(Currency),
currencies: this.exchangeRateDataService.getCurrencies(),
demoAuthToken: this.getDemoAuthToken(),
lastDataGathering: await this.getLastDataGathering(),
statistics: await this.getStatistics(),
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/order/create-order.dto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Currency, DataSource, Type } from '@prisma/client';
import { DataSource, Type } from '@prisma/client';
import { IsISO8601, IsNumber, IsString } from 'class-validator';

export class CreateOrderDto {
@IsString()
accountId: string;

@IsString()
currency: Currency;
currency: string;

@IsString()
dataSource: DataSource;
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/app/order/update-order.dto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Currency, DataSource, Type } from '@prisma/client';
import { IsISO8601, IsNumber, IsString, ValidateIf } from 'class-validator';
import { DataSource, Type } from '@prisma/client';
import { IsISO8601, IsNumber, IsString } from 'class-validator';

export class UpdateOrderDto {
@IsString()
accountId: string;

@IsString()
currency: Currency;
currency: string;

@IsString()
dataSource: DataSource;
Expand Down
12 changes: 6 additions & 6 deletions apps/api/src/app/portfolio/current-rate.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { Currency, DataSource, MarketData } from '@prisma/client';
import { DataSource, MarketData } from '@prisma/client';

import { CurrentRateService } from './current-rate.service';
import { MarketDataService } from './market-data.service';
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('CurrentRateService', () => {
null,
null
);
exchangeRateDataService = new ExchangeRateDataService(null);
exchangeRateDataService = new ExchangeRateDataService(null, null);
marketDataService = new MarketDataService(null);

await exchangeRateDataService.initialize();
Expand All @@ -95,10 +95,10 @@ describe('CurrentRateService', () => {
it('getValue', async () => {
expect(
await currentRateService.getValue({
currency: Currency.USD,
currency: 'USD',
date: new Date(Date.UTC(2020, 0, 1, 0, 0, 0)),
symbol: 'AMZN',
userCurrency: Currency.CHF
userCurrency: 'CHF'
})
).toMatchObject({
marketPrice: 1847.839966
Expand All @@ -108,13 +108,13 @@ describe('CurrentRateService', () => {
it('getValues', async () => {
expect(
await currentRateService.getValues({
currencies: { AMZN: Currency.USD },
currencies: { AMZN: 'USD' },
dataGatheringItems: [{ dataSource: DataSource.YAHOO, symbol: 'AMZN' }],
dateQuery: {
lt: new Date(Date.UTC(2020, 0, 2, 0, 0, 0)),
gte: new Date(Date.UTC(2020, 0, 1, 0, 0, 0))
},
userCurrency: Currency.CHF
userCurrency: 'CHF'
})
).toMatchObject([
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Currency } from '@prisma/client';

export interface GetValueParams {
currency: Currency;
currency: string;
date: Date;
symbol: string;
userCurrency: Currency;
userCurrency: string;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces';
import { Currency } from '@prisma/client';

import { DateQuery } from './date-query.interface';

export interface GetValuesParams {
currencies: { [symbol: string]: Currency };
currencies: { [symbol: string]: string };
dataGatheringItems: IDataGatheringItem[];
dateQuery: DateQuery;
userCurrency: Currency;
userCurrency: string;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { OrderType } from '@ghostfolio/api/models/order-type';
import { Currency, DataSource } from '@prisma/client';
import { DataSource } from '@prisma/client';
import Big from 'big.js';

export interface PortfolioOrder {
currency: Currency;
currency: string;
date: string;
dataSource: DataSource;
fee: Big;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Currency } from '@prisma/client';

export interface PortfolioPositionDetail {
averagePrice: number;
currency: Currency;
currency: string;
firstBuyDate: string;
grossPerformance: number;
grossPerformancePercent: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Currency, DataSource } from '@prisma/client';
import { DataSource } from '@prisma/client';
import Big from 'big.js';

export interface TransactionPointSymbol {
currency: Currency;
currency: string;
dataSource: DataSource;
fee: Big;
firstBuyDate: string;
Expand Down