diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index e50c0c77f..e6f5fd700 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -21,6 +21,7 @@ import { AdminUsersResponse, AssetProfileIdentifier } from '@ghostfolio/common/interfaces'; +import { PropertyKey } from '@ghostfolio/common/types'; import { BadRequestException, @@ -347,9 +348,14 @@ export class AdminService { let response: Property; if (value) { - response = await this.propertyService.put({ key, value }); + response = await this.propertyService.put({ + value, + key: key as PropertyKey + }); } else { - response = await this.propertyService.delete({ key }); + response = await this.propertyService.delete({ + key: key as PropertyKey + }); } if (key === PROPERTY_IS_READ_ONLY_MODE && value === 'true') { diff --git a/apps/api/src/services/property/property.service.ts b/apps/api/src/services/property/property.service.ts index 212635f49..80643482f 100644 --- a/apps/api/src/services/property/property.service.ts +++ b/apps/api/src/services/property/property.service.ts @@ -3,6 +3,7 @@ import { PROPERTY_CURRENCIES, PROPERTY_IS_USER_SIGNUP_ENABLED } from '@ghostfolio/common/config'; +import { PropertyKey } from '@ghostfolio/common/types'; import { Injectable } from '@nestjs/common'; @@ -12,7 +13,7 @@ import { PropertyValue } from './interfaces/interfaces'; export class PropertyService { public constructor(private readonly prismaService: PrismaService) {} - public async delete({ key }: { key: string }) { + public async delete({ key }: { key: PropertyKey }) { return this.prismaService.property.delete({ where: { key } }); @@ -40,7 +41,7 @@ export class PropertyService { return response; } - public async getByKey(aKey: string) { + public async getByKey(aKey: PropertyKey) { const properties = await this.get(); return properties[aKey] as TValue; } @@ -51,7 +52,7 @@ export class PropertyService { ); } - public async put({ key, value }: { key: string; value: string }) { + public async put({ key, value }: { key: PropertyKey; value: string }) { return this.prismaService.property.upsert({ create: { key, value }, update: { value }, diff --git a/libs/common/src/lib/types/index.ts b/libs/common/src/lib/types/index.ts index aefaf3e11..aa6893bc6 100644 --- a/libs/common/src/lib/types/index.ts +++ b/libs/common/src/lib/types/index.ts @@ -18,6 +18,7 @@ import type { Market } from './market.type'; import type { OrderWithAccount } from './order-with-account.type'; import type { ProductCategory } from './product-category.type'; import type { ProductPlatform } from './product-platform.type'; +import type { PropertyKey } from './property-key.type'; import type { RequestWithUser } from './request-with-user.type'; import type { SectorName } from './sector-name.type'; import type { SubscriptionOfferKey } from './subscription-offer-key.type'; @@ -45,6 +46,7 @@ export type { OrderWithAccount, ProductCategory, ProductPlatform, + PropertyKey, RequestWithUser, SectorName, SubscriptionOfferKey, diff --git a/libs/common/src/lib/types/property-key.type.ts b/libs/common/src/lib/types/property-key.type.ts new file mode 100644 index 000000000..6c89a5054 --- /dev/null +++ b/libs/common/src/lib/types/property-key.type.ts @@ -0,0 +1,7 @@ +import type * as config from '../config'; + +export type PropertyKey = { + [Key in keyof typeof config]: Key extends `PROPERTY_${string}` + ? (typeof config)[Key] + : never; +}[keyof typeof config];