Browse Source

Refactoring

pull/3725/head
Thomas Kaul 12 months ago
parent
commit
1280f7c990
  1. 6
      apps/api/src/app/portfolio/calculator/portfolio-calculator.factory.ts
  2. 12
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  3. 6
      apps/api/src/services/portfolio-snapshot/portfolio-snapshot.processor.ts

6
apps/api/src/app/portfolio/calculator/portfolio-calculator.factory.ts

@ -23,7 +23,7 @@ export class PortfolioCalculatorFactory {
private readonly configurationService: ConfigurationService, private readonly configurationService: ConfigurationService,
private readonly currentRateService: CurrentRateService, private readonly currentRateService: CurrentRateService,
private readonly exchangeRateDataService: ExchangeRateDataService, private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly portfolioService: PortfolioSnapshotService, private readonly portfolioSnapshotService: PortfolioSnapshotService,
private readonly redisCacheService: RedisCacheService private readonly redisCacheService: RedisCacheService
) {} ) {}
@ -53,7 +53,7 @@ export class PortfolioCalculatorFactory {
configurationService: this.configurationService, configurationService: this.configurationService,
currentRateService: this.currentRateService, currentRateService: this.currentRateService,
exchangeRateDataService: this.exchangeRateDataService, exchangeRateDataService: this.exchangeRateDataService,
portfolioService: this.portfolioService, portfolioSnapshotService: this.portfolioSnapshotService,
redisCacheService: this.redisCacheService redisCacheService: this.redisCacheService
}); });
case PerformanceCalculationType.TWR: case PerformanceCalculationType.TWR:
@ -66,7 +66,7 @@ export class PortfolioCalculatorFactory {
userId, userId,
configurationService: this.configurationService, configurationService: this.configurationService,
exchangeRateDataService: this.exchangeRateDataService, exchangeRateDataService: this.exchangeRateDataService,
portfolioService: this.portfolioService, portfolioSnapshotService: this.portfolioSnapshotService,
redisCacheService: this.redisCacheService redisCacheService: this.redisCacheService
}); });
default: default:

12
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -64,7 +64,7 @@ export abstract class PortfolioCalculator {
private endDate: Date; private endDate: Date;
private exchangeRateDataService: ExchangeRateDataService; private exchangeRateDataService: ExchangeRateDataService;
private filters: Filter[]; private filters: Filter[];
private portfolioService: PortfolioSnapshotService; private portfolioSnapshotService: PortfolioSnapshotService;
private redisCacheService: RedisCacheService; private redisCacheService: RedisCacheService;
private snapshot: PortfolioSnapshot; private snapshot: PortfolioSnapshot;
private snapshotPromise: Promise<void>; private snapshotPromise: Promise<void>;
@ -80,7 +80,7 @@ export abstract class PortfolioCalculator {
currentRateService, currentRateService,
exchangeRateDataService, exchangeRateDataService,
filters, filters,
portfolioService, portfolioSnapshotService,
redisCacheService, redisCacheService,
userId userId
}: { }: {
@ -91,7 +91,7 @@ export abstract class PortfolioCalculator {
currentRateService: CurrentRateService; currentRateService: CurrentRateService;
exchangeRateDataService: ExchangeRateDataService; exchangeRateDataService: ExchangeRateDataService;
filters: Filter[]; filters: Filter[];
portfolioService: PortfolioSnapshotService; portfolioSnapshotService: PortfolioSnapshotService;
redisCacheService: RedisCacheService; redisCacheService: RedisCacheService;
userId: string; userId: string;
}) { }) {
@ -140,7 +140,7 @@ export abstract class PortfolioCalculator {
return a.date?.localeCompare(b.date); return a.date?.localeCompare(b.date);
}); });
this.portfolioService = portfolioService; this.portfolioSnapshotService = portfolioSnapshotService;
this.redisCacheService = redisCacheService; this.redisCacheService = redisCacheService;
this.userId = userId; this.userId = userId;
@ -1078,7 +1078,7 @@ export abstract class PortfolioCalculator {
if (isCachedPortfolioSnapshotExpired) { if (isCachedPortfolioSnapshotExpired) {
// Compute in the background // Compute in the background
this.portfolioService.addJobToQueue({ this.portfolioSnapshotService.addJobToQueue({
data: { data: {
userId: this.userId userId: this.userId
}, },
@ -1094,7 +1094,7 @@ export abstract class PortfolioCalculator {
} else { } else {
// Wait for computation // Wait for computation
// TODO // TODO
const job = await this.portfolioService.addJobToQueue({ const job = await this.portfolioSnapshotService.addJobToQueue({
data: { data: {
userId: this.userId userId: this.userId
}, },

6
apps/api/src/services/portfolio-snapshot/portfolio-snapshot.processor.ts

@ -23,7 +23,7 @@ export class PortfolioSnapshotProcessor {
try { try {
Logger.log( Logger.log(
`Portfolio snapshot calculation of user ${job.data.userId} has been started`, `Portfolio snapshot calculation of user ${job.data.userId} has been started`,
`PortfolioProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})` `PortfolioSnapshotProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})`
); );
// TODO: Do something // TODO: Do something
@ -31,12 +31,12 @@ export class PortfolioSnapshotProcessor {
Logger.log( Logger.log(
`Portfolio snapshot calculation of user ${job.data.userId} has been completed`, `Portfolio snapshot calculation of user ${job.data.userId} has been completed`,
`PortfolioProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})` `PortfolioSnapshotProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})`
); );
} catch (error) { } catch (error) {
Logger.error( Logger.error(
error, error,
`PortfolioProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})` `PortfolioSnapshotProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})`
); );
throw new Error(error); throw new Error(error);

Loading…
Cancel
Save