Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/refactor getByKey() in PropertyService (#5065)
csehatt7418b9b1c7f1158
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0afaf54e6d..9a3544bfca 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).+## Unreleased++### Changed++- Made the `getByKey()` function generic in the property service+## 2.176.0 - 2025-06-30### Addeddiff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.tsindex ed55198f0b..9e645c0594 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<string[]>(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.tsindex e56ee062d6..b479d74eac 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<string>(PROPERTY_API_KEY_OPENROUTER- )) as string;+ );- const openRouterModel = (await this.propertyService.getByKey(+ const openRouterModel = await this.propertyService.getByKey<string>(PROPERTY_OPENROUTER_MODEL- )) as string;+ );const openRouterService = createOpenRouter({apiKey: openRouterApiKeydiff --git a/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts b/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.tsindex bdaecf7184..f80633f872 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<string>(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.tsindex 327245adee..6b6c40fbbc 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<boolean>(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<string[]>(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<string>(PROPERTY_SLACK_COMMUNITY_USERS- )) as string;+ );}private async getDemoAuthToken() {- const demoUserId = (await this.propertyService.getByKey(+ const demoUserId = await this.propertyService.getByKey<string>(PROPERTY_DEMO_USER_ID- )) as string;+ );if (demoUserId) {return this.jwtService.sign({@@ -298,9 +298,9 @@ export class InfoService {private async getUptime(): Promise<number> {{try {- const monitorId = (await this.propertyService.getByKey(+ const monitorId = await this.propertyService.getByKey<string>(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.tsindex f37543fdff..244a6b806d 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<Coupon[]>(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.tsindex ae0e443e48..679d4590df 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<any>(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<any>(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.tsindex 0ca3fda337..3ad43301e1 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<SystemMessage>(+ 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<boolean>(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.tsindex f37f26bfcf..4b1d9a65f6 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<Partial<SymbolProfile>[]> {const symbolProfileIds: string[] = (- ((await this.propertyService.getByKey(+ (await this.propertyService.getByKey<BenchmarkProperty[]>(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<BenchmarkProperty[]>(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<BenchmarkProperty[]>(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.tsindex 606da5b884..a850991f3b 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<string>(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.tsindex 90354ace52..3fd9e1bea4 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<string>(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.tsindex 477b43e3b1..8f3658736f 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<string>(PROPERTY_DEMO_ACCOUNT_ID),+ this.propertyService.getByKey<string>(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.tsindex 0a2d177ce2..433547c945 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<string[]>(PROPERTY_CURRENCIES);if (customCurrencies?.length > 0) {currencies = currencies.concat(customCurrencies);diff --git a/apps/api/src/services/property/interfaces/interfaces.ts b/apps/api/src/services/property/interfaces/interfaces.tsnew file mode 100644index 0000000000..be9bc530d1--- /dev/null+++ b/apps/api/src/services/property/interfaces/interfaces.ts@@ -0,0 +1 @@+export type PropertyValue = boolean | object | string | string[];diff --git a/apps/api/src/services/property/property.service.ts b/apps/api/src/services/property/property.service.tsindex 34ce5713b7..212635f498 100644--- a/apps/api/src/services/property/property.service.ts+++ b/apps/api/src/services/property/property.service.ts@@ -6,6 +6,8 @@ import {import { Injectable } from '@nestjs/common';+import { PropertyValue } from './interfaces/interfaces';+@Injectable()export class PropertyService {public constructor(private readonly prismaService: PrismaService) {}@@ -18,7 +20,7 @@ export class PropertyService {public async get() {const response: {- [key: string]: boolean | object | string | string[];+ [key: string]: PropertyValue;} = {[PROPERTY_CURRENCIES]: []};@@ -38,15 +40,14 @@ export class PropertyService {return response;}- public async getByKey(aKey: string) {+ public async getByKey<TValue extends PropertyValue>(aKey: string) {const properties = await this.get();- return properties?.[aKey];+ return properties[aKey] as TValue;}public async isUserSignupEnabled() {return (- ((await this.getByKey(PROPERTY_IS_USER_SIGNUP_ENABLED)) as boolean) ??- true+ (await this.getByKey<boolean>(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.tsindex 0f1537d02c..31edf6ffca 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<IDataGatheringItem[]> {const benchmarkAssetProfileIdMap: { [key: string]: boolean } = {};(- ((await this.propertyService.getByKey(+ (await this.propertyService.getByKey<BenchmarkProperty[]>(PROPERTY_BENCHMARKS- )) as BenchmarkProperty[]) ?? []+ )) ?? []).forEach(({ symbolProfileId }) => {benchmarkAssetProfileIdMap[symbolProfileId] = true;});