Browse Source

Refactoring

pull/452/head
Thomas 4 years ago
parent
commit
7c240e3f2d
  1. 12
      README.md
  2. 7
      apps/api/src/services/data-gathering.service.ts
  3. 12
      apps/api/src/services/interfaces/symbol-profile.interface.ts
  4. 15
      apps/api/src/services/symbol-profile.service.ts
  5. 3
      package.json
  6. 2
      prisma/migrations/20211107082008_added_symbol_mapping_to_symbol_profile/migration.sql
  7. 2
      prisma/schema.prisma

12
README.md

@ -101,7 +101,7 @@ docker-compose -f docker/docker-compose-build-local.yml up
Run the following command to setup the database once Ghostfolio is running: Run the following command to setup the database once Ghostfolio is running:
```bash ```bash
docker-compose -f docker/docker-compose-build-local.yml exec ghostfolio yarn setup:database docker-compose -f docker/docker-compose-build-local.yml exec ghostfolio yarn database:setup
``` ```
### Fetch Historical Data ### Fetch Historical Data
@ -112,6 +112,14 @@ Open http://localhost:3333 in your browser and accomplish these steps:
1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data 1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data
1. Click _Sign out_ and check out the _Live Demo_ 1. Click _Sign out_ and check out the _Live Demo_
### Migrate Database
With the following command you can keep your database schema in sync after a Ghostfolio version update:
```bash
docker-compose -f docker/docker-compose-build-local.yml exec ghostfolio yarn database:migrate
```
## Development ## Development
### Prerequisites ### Prerequisites
@ -126,7 +134,7 @@ Open http://localhost:3333 in your browser and accomplish these steps:
1. Run `cd docker` 1. Run `cd docker`
1. Run `docker compose up -d` to start [PostgreSQL](https://www.postgresql.org) and [Redis](https://redis.io) 1. Run `docker compose up -d` to start [PostgreSQL](https://www.postgresql.org) and [Redis](https://redis.io)
1. Run `cd -` to go back to the project root directory 1. Run `cd -` to go back to the project root directory
1. Run `yarn setup:database` to initialize the database schema and populate your database with (example) data 1. Run `yarn database:setup` to initialize the database schema and populate your database with (example) data
1. Start server and client (see [_Development_](#Development)) 1. Start server and client (see [_Development_](#Development))
1. Login as _Admin_ with the following _Security Token_: `ae76872ae8f3419c6d6f64bf51888ecbcc703927a342d815fafe486acdb938da07d0cf44fca211a0be74a423238f535362d390a41e81e633a9ce668a6e31cdf9` 1. Login as _Admin_ with the following _Security Token_: `ae76872ae8f3419c6d6f64bf51888ecbcc703927a342d815fafe486acdb938da07d0cf44fca211a0be74a423238f535362d390a41e81e633a9ce668a6e31cdf9`
1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data 1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data

7
apps/api/src/services/data-gathering.service.ts

@ -141,10 +141,9 @@ export class DataGatheringService {
); );
for (const [symbol, response] of Object.entries(currentData)) { for (const [symbol, response] of Object.entries(currentData)) {
const symbolMapping = const symbolMapping = symbolProfiles.find((symbolProfile) => {
symbolProfiles.find((symbolProfile) => { return symbolProfile.symbol === symbol;
return symbolProfile.symbol === symbol; })?.symbolMapping;
})?.settings?.symbolMapping ?? {};
for (const dataEnhancer of this.dataEnhancers) { for (const dataEnhancer of this.dataEnhancers) {
try { try {

12
apps/api/src/services/interfaces/symbol-profile.interface.ts

@ -5,18 +5,14 @@ import { AssetClass, AssetSubClass, DataSource } from '@prisma/client';
export interface EnhancedSymbolProfile { export interface EnhancedSymbolProfile {
assetClass: AssetClass; assetClass: AssetClass;
assetSubClass: AssetSubClass; assetSubClass: AssetSubClass;
countries: Country[];
createdAt: Date; createdAt: Date;
currency: string | null; currency: string | null;
dataSource: DataSource; dataSource: DataSource;
id: string; id: string;
name: string | null; name: string | null;
updatedAt: Date;
settings?: SymbolProfileSettings;
symbol: string;
countries: Country[];
sectors: Sector[]; sectors: Sector[];
} symbol: string;
symbolMapping?: { [key: string]: string };
export interface SymbolProfileSettings { updatedAt: Date;
symbolMapping: { [key: string]: string };
} }

15
apps/api/src/services/symbol-profile.service.ts

@ -1,7 +1,4 @@
import { import { EnhancedSymbolProfile } from '@ghostfolio/api/services/interfaces/symbol-profile.interface';
EnhancedSymbolProfile,
SymbolProfileSettings
} from '@ghostfolio/api/services/interfaces/symbol-profile.interface';
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { UNKNOWN_KEY } from '@ghostfolio/common/config'; import { UNKNOWN_KEY } from '@ghostfolio/common/config';
import { Country } from '@ghostfolio/common/interfaces/country.interface'; import { Country } from '@ghostfolio/common/interfaces/country.interface';
@ -33,7 +30,7 @@ export class SymbolProfileService {
...symbolProfile, ...symbolProfile,
countries: this.getCountries(symbolProfile), countries: this.getCountries(symbolProfile),
sectors: this.getSectors(symbolProfile), sectors: this.getSectors(symbolProfile),
settings: this.getSettings(symbolProfile) symbolMapping: this.getSymbolMapping(symbolProfile)
})); }));
} }
@ -66,7 +63,11 @@ export class SymbolProfileService {
); );
} }
private getSettings(symbolProfile: SymbolProfile): SymbolProfileSettings { private getSymbolMapping(symbolProfile: SymbolProfile) {
return { symbolMapping: symbolProfile.settings['symbolMapping'] }; return (
(symbolProfile['symbolMapping'] as {
[key: string]: string;
}) ?? {}
);
} }
} }

3
package.json

@ -19,8 +19,10 @@
"database:format-schema": "prisma format", "database:format-schema": "prisma format",
"database:generate-typings": "prisma generate", "database:generate-typings": "prisma generate",
"database:gui": "prisma studio", "database:gui": "prisma studio",
"database:migrate": "prisma migrate deploy",
"database:push": "prisma db push", "database:push": "prisma db push",
"database:seed": "prisma db seed --preview-feature", "database:seed": "prisma db seed --preview-feature",
"database:setup": "yarn database:push && yarn database:seed",
"dep-graph": "nx dep-graph", "dep-graph": "nx dep-graph",
"e2e": "ng e2e", "e2e": "ng e2e",
"format": "nx format:write", "format": "nx format:write",
@ -33,7 +35,6 @@
"nx": "nx", "nx": "nx",
"postinstall": "prisma generate && ngcc --properties es2015 browser module main", "postinstall": "prisma generate && ngcc --properties es2015 browser module main",
"replace-placeholders-in-build": "node ./replace.build.js", "replace-placeholders-in-build": "node ./replace.build.js",
"setup:database": "yarn database:push && yarn database:seed",
"start": "node dist/apps/api/main", "start": "node dist/apps/api/main",
"start:client": "ng serve client --hmr -o", "start:client": "ng serve client --hmr -o",
"start:prod": "node apps/api/main", "start:prod": "node apps/api/main",

2
prisma/migrations/20211107082008_added_symbol_mapping_to_symbol_profile/migration.sql

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "SymbolProfile" ADD COLUMN "symbolMapping" JSONB;

2
prisma/schema.prisma

@ -127,10 +127,10 @@ model SymbolProfile {
id String @id @default(uuid()) id String @id @default(uuid())
name String? name String?
Order Order[] Order Order[]
settings Json?
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
sectors Json? sectors Json?
symbol String symbol String
symbolMapping Json?
@@unique([dataSource, symbol]) @@unique([dataSource, symbol])
} }

Loading…
Cancel
Save