diff --git a/apps/api/src/app/app.controller.ts b/apps/api/src/app/app.controller.ts index f7704f9e2..32a4982fe 100644 --- a/apps/api/src/app/app.controller.ts +++ b/apps/api/src/app/app.controller.ts @@ -1,6 +1,20 @@ +import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; +import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { Controller } from '@nestjs/common'; @Controller() export class AppController { - public constructor() {} + public constructor( + private readonly exchangeRateDataService: ExchangeRateDataService, + private readonly prismaService: PrismaService + ) { + this.initialize(); + } + + private async initialize() { + try { + await this.prismaService.$connect(); + await this.exchangeRateDataService.initialize(); + } catch {} + } } diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index b66b40866..6b12bd723 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -21,7 +21,7 @@ import { } from '@prisma/client'; import Big from 'big.js'; import { endOfToday, isAfter } from 'date-fns'; -import { groupBy, isString } from 'lodash'; +import { groupBy } from 'lodash'; import { v4 as uuidv4 } from 'uuid'; import { Activity } from './interfaces/activities.interface'; diff --git a/apps/api/src/services/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data.service.ts index 25ccc73b8..8808698f5 100644 --- a/apps/api/src/services/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data.service.ts @@ -22,9 +22,7 @@ export class ExchangeRateDataService { private readonly dataProviderService: DataProviderService, private readonly prismaService: PrismaService, private readonly propertyService: PropertyService - ) { - this.initialize(); - } + ) {} public getCurrencies() { return this.currencies?.length > 0 ? this.currencies : [this.baseCurrency]; diff --git a/apps/api/src/services/prisma.service.ts b/apps/api/src/services/prisma.service.ts index f3555e2a5..e99d6ecf9 100644 --- a/apps/api/src/services/prisma.service.ts +++ b/apps/api/src/services/prisma.service.ts @@ -1,15 +1,25 @@ -import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; +import { + Injectable, + Logger, + OnModuleDestroy, + OnModuleInit +} from '@nestjs/common'; import { PrismaClient } from '@prisma/client'; @Injectable() export class PrismaService extends PrismaClient - implements OnModuleInit, OnModuleDestroy { - async onModuleInit() { - await this.$connect(); + implements OnModuleInit, OnModuleDestroy +{ + public async onModuleInit() { + try { + await this.$connect(); + } catch (error) { + Logger.error(error, 'PrismaService'); + } } - async onModuleDestroy() { + public async onModuleDestroy() { await this.$disconnect(); } }