From 5016f8b5863c3d0ac8a7454f06a65a8f5a2ce046 Mon Sep 17 00:00:00 2001 From: csehatt741 Date: Mon, 30 Jun 2025 13:17:56 +0200 Subject: [PATCH] PropertyService.getByKey() made generic --- apps/api/src/app/admin/admin.service.ts | 5 ++--- apps/api/src/app/endpoints/ai/ai.service.ts | 8 ++++---- .../ghostfolio/ghostfolio.service.ts | 4 ++-- apps/api/src/app/info/info.service.ts | 20 +++++++++---------- .../subscription/subscription.controller.ts | 3 +-- .../app/subscription/subscription.service.ts | 6 ++---- apps/api/src/app/user/user.service.ts | 11 +++++----- .../services/benchmark/benchmark.service.ts | 12 +++++------ .../data-provider/data-provider.service.ts | 8 ++++---- .../ghostfolio/ghostfolio.service.ts | 4 ++-- apps/api/src/services/demo/demo.service.ts | 8 ++++---- .../exchange-rate-data.service.ts | 5 ++--- .../src/services/property/property.service.ts | 3 +-- .../data-gathering/data-gathering.service.ts | 4 ++-- 14 files changed, 48 insertions(+), 53 deletions(-) diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index ed55198f0..9e645c059 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -114,9 +114,8 @@ export class AdminService { await this.marketDataService.deleteMany({ dataSource, symbol }); const currency = getCurrencyFromSymbol(symbol); - const customCurrencies = (await this.propertyService.getByKey( - PROPERTY_CURRENCIES - )) as string[]; + const customCurrencies = + await this.propertyService.getByKey(PROPERTY_CURRENCIES); if (customCurrencies.includes(currency)) { const updatedCustomCurrencies = customCurrencies.filter( diff --git a/apps/api/src/app/endpoints/ai/ai.service.ts b/apps/api/src/app/endpoints/ai/ai.service.ts index e56ee062d..b479d74ea 100644 --- a/apps/api/src/app/endpoints/ai/ai.service.ts +++ b/apps/api/src/app/endpoints/ai/ai.service.ts @@ -19,13 +19,13 @@ export class AiService { ) {} public async generateText({ prompt }: { prompt: string }) { - const openRouterApiKey = (await this.propertyService.getByKey( + const openRouterApiKey = await this.propertyService.getByKey( PROPERTY_API_KEY_OPENROUTER - )) as string; + ); - const openRouterModel = (await this.propertyService.getByKey( + const openRouterModel = await this.propertyService.getByKey( PROPERTY_OPENROUTER_MODEL - )) as string; + ); const openRouterService = createOpenRouter({ apiKey: openRouterApiKey diff --git a/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts b/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts index bdaecf718..f80633f87 100644 --- a/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts +++ b/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts @@ -164,9 +164,9 @@ export class GhostfolioService { public async getMaxDailyRequests() { return parseInt( - ((await this.propertyService.getByKey( + (await this.propertyService.getByKey( PROPERTY_DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS - )) as string) || '0', + )) || '0', 10 ); } diff --git a/apps/api/src/app/info/info.service.ts b/apps/api/src/app/info/info.service.ts index 327245ade..6b6c40fbb 100644 --- a/apps/api/src/app/info/info.service.ts +++ b/apps/api/src/app/info/info.service.ts @@ -64,9 +64,9 @@ export class InfoService { } if (this.configurationService.get('ENABLE_FEATURE_READ_ONLY_MODE')) { - isReadOnlyMode = (await this.propertyService.getByKey( + isReadOnlyMode = await this.propertyService.getByKey( PROPERTY_IS_READ_ONLY_MODE - )) as boolean; + ); } if (this.configurationService.get('ENABLE_FEATURE_SOCIAL_LOGIN')) { @@ -81,9 +81,9 @@ export class InfoService { globalPermissions.push(permissions.enableSubscription); info.countriesOfSubscribers = - ((await this.propertyService.getByKey( + (await this.propertyService.getByKey( PROPERTY_COUNTRIES_OF_SUBSCRIBERS - )) as string[]) ?? []; + )) ?? []; info.stripePublicKey = this.configurationService.get('STRIPE_PUBLIC_KEY'); } @@ -230,15 +230,15 @@ export class InfoService { } private async countSlackCommunityUsers() { - return (await this.propertyService.getByKey( + return await this.propertyService.getByKey( PROPERTY_SLACK_COMMUNITY_USERS - )) as string; + ); } private async getDemoAuthToken() { - const demoUserId = (await this.propertyService.getByKey( + const demoUserId = await this.propertyService.getByKey( PROPERTY_DEMO_USER_ID - )) as string; + ); if (demoUserId) { return this.jwtService.sign({ @@ -298,9 +298,9 @@ export class InfoService { private async getUptime(): Promise { { try { - const monitorId = (await this.propertyService.getByKey( + const monitorId = await this.propertyService.getByKey( PROPERTY_BETTER_UPTIME_MONITOR_ID - )) as string; + ); const { data } = await fetch( `https://uptime.betterstack.com/api/v2/monitors/${monitorId}/sla?from=${format( diff --git a/apps/api/src/app/subscription/subscription.controller.ts b/apps/api/src/app/subscription/subscription.controller.ts index f37543fdf..244a6b806 100644 --- a/apps/api/src/app/subscription/subscription.controller.ts +++ b/apps/api/src/app/subscription/subscription.controller.ts @@ -49,8 +49,7 @@ export class SubscriptionController { } let coupons = - ((await this.propertyService.getByKey(PROPERTY_COUPONS)) as Coupon[]) ?? - []; + (await this.propertyService.getByKey(PROPERTY_COUPONS)) ?? []; const coupon = coupons.find((currentCoupon) => { return currentCoupon.code === couponCode; diff --git a/apps/api/src/app/subscription/subscription.service.ts b/apps/api/src/app/subscription/subscription.service.ts index ae0e443e4..679d4590d 100644 --- a/apps/api/src/app/subscription/subscription.service.ts +++ b/apps/api/src/app/subscription/subscription.service.ts @@ -50,8 +50,7 @@ export class SubscriptionService { const subscriptionOffers: { [offer in SubscriptionOfferKey]: SubscriptionOffer; } = - ((await this.propertyService.getByKey(PROPERTY_STRIPE_CONFIG)) as any) ?? - {}; + (await this.propertyService.getByKey(PROPERTY_STRIPE_CONFIG)) ?? {}; const subscriptionOffer = Object.values(subscriptionOffers).find( (subscriptionOffer) => { @@ -213,8 +212,7 @@ export class SubscriptionService { const offers: { [offer in SubscriptionOfferKey]: SubscriptionOffer; } = - ((await this.propertyService.getByKey(PROPERTY_STRIPE_CONFIG)) as any) ?? - {}; + (await this.propertyService.getByKey(PROPERTY_STRIPE_CONFIG)) ?? {}; return { ...offers[key], diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 0ca3fda33..3ad43301e 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -125,9 +125,10 @@ export class UserService { let systemMessage: SystemMessage; - const systemMessageProperty = (await this.propertyService.getByKey( - PROPERTY_SYSTEM_MESSAGE - )) as SystemMessage; + const systemMessageProperty = + await this.propertyService.getByKey( + PROPERTY_SYSTEM_MESSAGE + ); if (systemMessageProperty?.targetGroups?.includes(subscription?.type)) { systemMessage = systemMessageProperty; @@ -443,9 +444,9 @@ export class UserService { currentPermissions.push(permissions.toggleReadOnlyMode); } - const isReadOnlyMode = (await this.propertyService.getByKey( + const isReadOnlyMode = await this.propertyService.getByKey( PROPERTY_IS_READ_ONLY_MODE - )) as boolean; + ); if (isReadOnlyMode) { currentPermissions = currentPermissions.filter((permission) => { diff --git a/apps/api/src/services/benchmark/benchmark.service.ts b/apps/api/src/services/benchmark/benchmark.service.ts index f37f26bfc..4b1d9a65f 100644 --- a/apps/api/src/services/benchmark/benchmark.service.ts +++ b/apps/api/src/services/benchmark/benchmark.service.ts @@ -106,9 +106,9 @@ export class BenchmarkService { enableSharing = false } = {}): Promise[]> { const symbolProfileIds: string[] = ( - ((await this.propertyService.getByKey( + (await this.propertyService.getByKey( PROPERTY_BENCHMARKS - )) as BenchmarkProperty[]) ?? [] + )) ?? [] ) .filter((benchmark) => { if (enableSharing) { @@ -154,9 +154,9 @@ export class BenchmarkService { } let benchmarks = - ((await this.propertyService.getByKey( + (await this.propertyService.getByKey( PROPERTY_BENCHMARKS - )) as BenchmarkProperty[]) ?? []; + )) ?? []; benchmarks.push({ symbolProfileId: assetProfile.id }); @@ -191,9 +191,9 @@ export class BenchmarkService { } let benchmarks = - ((await this.propertyService.getByKey( + (await this.propertyService.getByKey( PROPERTY_BENCHMARKS - )) as BenchmarkProperty[]) ?? []; + )) ?? []; benchmarks = benchmarks.filter(({ symbolProfileId }) => { return symbolProfileId !== assetProfile.id; diff --git a/apps/api/src/services/data-provider/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.ts index 606da5b88..a850991f3 100644 --- a/apps/api/src/services/data-provider/data-provider.service.ts +++ b/apps/api/src/services/data-provider/data-provider.service.ts @@ -52,9 +52,9 @@ export class DataProviderService implements OnModuleInit { public async onModuleInit() { this.dataProviderMapping = - ((await this.propertyService.getByKey(PROPERTY_DATA_SOURCE_MAPPING)) as { + (await this.propertyService.getByKey<{ [dataProviderName: string]: string; - }) ?? {}; + }>(PROPERTY_DATA_SOURCE_MAPPING)) ?? {}; } public async checkQuote(dataSource: DataSource) { @@ -183,9 +183,9 @@ export class DataProviderService implements OnModuleInit { return DataSource[dataSource]; }); - const ghostfolioApiKey = (await this.propertyService.getByKey( + const ghostfolioApiKey = await this.propertyService.getByKey( PROPERTY_API_KEY_GHOSTFOLIO - )) as string; + ); if (includeGhostfolio || ghostfolioApiKey) { dataSources.push('GHOSTFOLIO'); diff --git a/apps/api/src/services/data-provider/ghostfolio/ghostfolio.service.ts b/apps/api/src/services/data-provider/ghostfolio/ghostfolio.service.ts index 90354ace5..3fd9e1bea 100644 --- a/apps/api/src/services/data-provider/ghostfolio/ghostfolio.service.ts +++ b/apps/api/src/services/data-provider/ghostfolio/ghostfolio.service.ts @@ -295,9 +295,9 @@ export class GhostfolioService implements DataProviderInterface { } private async getRequestHeaders() { - const apiKey = (await this.propertyService.getByKey( + const apiKey = await this.propertyService.getByKey( PROPERTY_API_KEY_GHOSTFOLIO - )) as string; + ); return { [HEADER_KEY_TOKEN]: `Api-Key ${apiKey}` diff --git a/apps/api/src/services/demo/demo.service.ts b/apps/api/src/services/demo/demo.service.ts index 477b43e3b..8f3658736 100644 --- a/apps/api/src/services/demo/demo.service.ts +++ b/apps/api/src/services/demo/demo.service.ts @@ -17,10 +17,10 @@ export class DemoService { ) {} public async syncDemoUserAccount() { - const [demoAccountId, demoUserId] = (await Promise.all([ - this.propertyService.getByKey(PROPERTY_DEMO_ACCOUNT_ID), - this.propertyService.getByKey(PROPERTY_DEMO_USER_ID) - ])) as [string, string]; + const [demoAccountId, demoUserId] = await Promise.all([ + this.propertyService.getByKey(PROPERTY_DEMO_ACCOUNT_ID), + this.propertyService.getByKey(PROPERTY_DEMO_USER_ID) + ]); let activities = await this.prismaService.order.findMany({ orderBy: { diff --git a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts index 0a2d177ce..433547c94 100644 --- a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts @@ -497,9 +497,8 @@ export class ExchangeRateDataService { currencies.push(currency); }); - const customCurrencies = (await this.propertyService.getByKey( - PROPERTY_CURRENCIES - )) as string[]; + const customCurrencies = + await this.propertyService.getByKey(PROPERTY_CURRENCIES); if (customCurrencies?.length > 0) { currencies = currencies.concat(customCurrencies); diff --git a/apps/api/src/services/property/property.service.ts b/apps/api/src/services/property/property.service.ts index 8c1d72373..37944eb1b 100644 --- a/apps/api/src/services/property/property.service.ts +++ b/apps/api/src/services/property/property.service.ts @@ -45,8 +45,7 @@ export class PropertyService { public async isUserSignupEnabled() { return ( - ((await this.getByKey(PROPERTY_IS_USER_SIGNUP_ENABLED)) as boolean) ?? - true + (await this.getByKey(PROPERTY_IS_USER_SIGNUP_ENABLED)) ?? true ); } diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts index 0f1537d02..31edf6ffc 100644 --- a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts +++ b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts @@ -406,9 +406,9 @@ export class DataGatheringService { private async getSymbolsMax(): Promise { const benchmarkAssetProfileIdMap: { [key: string]: boolean } = {}; ( - ((await this.propertyService.getByKey( + (await this.propertyService.getByKey( PROPERTY_BENCHMARKS - )) as BenchmarkProperty[]) ?? [] + )) ?? [] ).forEach(({ symbolProfileId }) => { benchmarkAssetProfileIdMap[symbolProfileId] = true; });