diff --git a/apps/api/src/app/endpoints/watchlist/watchlist.controller.ts b/apps/api/src/app/endpoints/watchlist/watchlist.controller.ts index de6f43d4f..5c5bb733b 100644 --- a/apps/api/src/app/endpoints/watchlist/watchlist.controller.ts +++ b/apps/api/src/app/endpoints/watchlist/watchlist.controller.ts @@ -2,6 +2,7 @@ import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorat import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.interceptor'; import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.interceptor'; +import { WatchlistResponse } from '@ghostfolio/common/interfaces'; import { permissions } from '@ghostfolio/common/permissions'; import { RequestWithUser } from '@ghostfolio/common/types'; @@ -54,7 +55,7 @@ export class WatchlistController { ) { const watchlistItem = await this.watchlistService .getWatchlistItems(this.request.user.id) - .then(({ watchlist }) => { + .then((watchlist) => { return watchlist.find((item) => { return item.dataSource === dataSource && item.symbol === symbol; }); @@ -78,7 +79,13 @@ export class WatchlistController { @HasPermission(permissions.readWatchlist) @UseGuards(AuthGuard('jwt'), HasPermissionGuard) @UseInterceptors(TransformDataSourceInResponseInterceptor) - public async getWatchlistItems() { - return this.watchlistService.getWatchlistItems(this.request.user.id); + public async getWatchlistItems(): Promise { + const watchlist = await this.watchlistService.getWatchlistItems( + this.request.user.id + ); + + return { + watchlist + }; } } diff --git a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts index ab7ed88a4..c086c5f0e 100644 --- a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts +++ b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts @@ -64,7 +64,7 @@ export class WatchlistService { public async getWatchlistItems( userId: string - ): Promise<{ watchlist: AssetProfileIdentifier[] }> { + ): Promise { const user = await this.prismaService.user.findUnique({ select: { watchlist: { @@ -74,6 +74,6 @@ export class WatchlistService { where: { id: userId } }); - return { watchlist: user.watchlist ?? [] }; + return user?.watchlist ?? []; } } diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts index 6a9a164a1..526c61972 100644 --- a/apps/client/src/app/services/data.service.ts +++ b/apps/client/src/app/services/data.service.ts @@ -45,7 +45,8 @@ import { PortfolioPerformanceResponse, PortfolioReportResponse, PublicPortfolioResponse, - User + User, + WatchlistResponse } from '@ghostfolio/common/interfaces'; import { filterGlobalPermissions } from '@ghostfolio/common/permissions'; import type { @@ -688,9 +689,7 @@ export class DataService { } public fetchWatchlist() { - return this.http.get<{ watchlist: AssetProfileIdentifier[] }>( - '/api/v1/watchlist' - ); + return this.http.get('/api/v1/watchlist'); } public generateAccessToken(aUserId: string) { diff --git a/libs/common/src/lib/interfaces/index.ts b/libs/common/src/lib/interfaces/index.ts index c93ab2d27..b83b6d5f8 100644 --- a/libs/common/src/lib/interfaces/index.ts +++ b/libs/common/src/lib/interfaces/index.ts @@ -57,6 +57,7 @@ import type { PortfolioPerformanceResponse } from './responses/portfolio-perform import type { PortfolioReportResponse } from './responses/portfolio-report.interface'; import type { PublicPortfolioResponse } from './responses/public-portfolio-response.interface'; import type { QuotesResponse } from './responses/quotes-response.interface'; +import type { WatchlistResponse } from './responses/watchlist-response.interface'; import type { ScraperConfiguration } from './scraper-configuration.interface'; import type { Statistics } from './statistics.interface'; import type { SubscriptionOffer } from './subscription-offer.interface'; @@ -135,5 +136,6 @@ export { ToggleOption, User, UserSettings, + WatchlistResponse, XRayRulesSettings }; diff --git a/libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts b/libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts new file mode 100644 index 000000000..3cdc834b4 --- /dev/null +++ b/libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts @@ -0,0 +1,5 @@ +import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces'; + +export interface WatchlistResponse { + watchlist: AssetProfileIdentifier[]; +}