Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Task/improve type safety in prisma, property, and redis cache services (#8355)
Kenrick Tandrianbbefa35f4ff2
diff --git a/apps/api/src/services/prisma/prisma.service.ts b/apps/api/src/services/prisma/prisma.service.tsindex fcf7c6e5ea..ece0fd8140 100644--- a/apps/api/src/services/prisma/prisma.service.ts+++ b/apps/api/src/services/prisma/prisma.service.ts@@ -25,7 +25,7 @@ export class PrismaServicetry {customLogLevels = JSON.parse(- configService.get<string>('LOG_LEVELS')+ configService.get<string>('LOG_LEVELS') ?? '') as LogLevel[];} catch {}diff --git a/apps/api/src/services/property/property.service.ts b/apps/api/src/services/property/property.service.tsindex 6d8130bbc2..4435fd220d 100644--- a/apps/api/src/services/property/property.service.ts+++ b/apps/api/src/services/property/property.service.ts@@ -16,8 +16,8 @@ import { PropertyValue } from './interfaces/interfaces';export class PropertyService {private static readonly CACHE_TTL = ms('1 minute');- private cachedProperties: Promise<Property[]>;- private cachedPropertiesExpiresAt: Date;+ private cachedProperties?: Promise<Property[]>;+ private cachedPropertiesExpiresAt?: Date;public constructor(private readonly prismaService: PrismaService) {}@@ -91,6 +91,7 @@ export class PropertyService {if (this.cachedProperties &&+ this.cachedPropertiesExpiresAt &&isBefore(new Date(), this.cachedPropertiesExpiresAt)) {return this.cachedProperties;diff --git a/apps/api/src/services/redis-cache/redis-cache.service.mock.ts b/apps/api/src/services/redis-cache/redis-cache.service.mock.tsindex 78ecda1c9d..77ee164a6f 100644--- a/apps/api/src/services/redis-cache/redis-cache.service.mock.ts+++ b/apps/api/src/services/redis-cache/redis-cache.service.mock.ts@@ -3,8 +3,8 @@ import { PerformanceCalculationType } from '@ghostfolio/common/types/performanceexport const RedisCacheServiceMock = {cache: new Map<string, string>(),- get: (key: string): Promise<string> => {- const value = RedisCacheServiceMock.cache.get(key) || null;+ get: (key: string): Promise<string | undefined> => {+ const value = RedisCacheServiceMock.cache.get(key);return Promise.resolve(value);},@@ -19,7 +19,7 @@ export const RedisCacheServiceMock = {}): string => {const filtersHash = filters?.length;- return `portfolio-snapshot-${userId}-${calculationType}${filtersHash > 0 ? `-${filtersHash}` : ''}`;+ return `portfolio-snapshot-${userId}-${calculationType}${filtersHash && filtersHash > 0 ? `-${filtersHash}` : ''}`;},reset: () => {RedisCacheServiceMock.cache.clear();diff --git a/apps/api/src/services/redis-cache/redis-cache.service.ts b/apps/api/src/services/redis-cache/redis-cache.service.tsindex 857d96e945..5e64f5a635 100644--- a/apps/api/src/services/redis-cache/redis-cache.service.ts+++ b/apps/api/src/services/redis-cache/redis-cache.service.ts@@ -33,7 +33,7 @@ export class RedisCacheService {});}- public async get(key: string): Promise<string> {+ public async get(key: string): Promise<string | undefined> {return this.cache.get(key);}@@ -42,9 +42,11 @@ export class RedisCacheService {const prefix = aPrefix;try {- for await (const [key] of this.client.iterator({})) {- if ((prefix && key.startsWith(prefix)) || !prefix) {- keys.push(key);+ if (this.client.iterator) {+ for await (const [key] of this.client.iterator({})) {+ if ((prefix && key.startsWith(prefix)) || !prefix) {+ keys.push(key);+ }}}} catch {}@@ -63,7 +65,7 @@ export class RedisCacheService {}) {let portfolioSnapshotKey = `${this.getPortfolioSnapshotKeyPrefix({ userId })}-${calculationType}`;- if (filters?.length > 0) {+ if (filters && filters.length > 0) {const filtersHash = createHash('sha256').update(JSON.stringify(filters)).digest('hex');