From f04ad05f900e2d1f0ac4caac8b5b03b4932375d2 Mon Sep 17 00:00:00 2001 From: KenTandrian Date: Sat, 7 Nov 2026 04:25:08 +0000 Subject: [PATCH] fix(api): improve type safety in queue and i18n services --- apps/api/src/services/i18n/i18n.service.ts | 2 +- .../data-gathering/data-gathering.service.ts | 29 ++++++++++++------- .../portfolio-snapshot.service.mock.ts | 4 ++- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/apps/api/src/services/i18n/i18n.service.ts b/apps/api/src/services/i18n/i18n.service.ts index 834b0a65e1..93fd829bf3 100644 --- a/apps/api/src/services/i18n/i18n.service.ts +++ b/apps/api/src/services/i18n/i18n.service.ts @@ -29,7 +29,7 @@ export class I18nService implements OnModuleInit { return routerLink.map((link) => { const match = link.match(I18nService.TRANSLATION_TAGGED_MESSAGE_REGEX); - const segment = match + const segment = match?.groups ? this.getTranslation({ languageCode, id: match.groups.id 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 fa96b1201c..18964db9a1 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 @@ -104,7 +104,11 @@ export class DataGatheringService { ); for (const assetProfile of Object.values(assetProfiles)) { - const { symbol } = assetProfile; + const { dataSource, symbol } = assetProfile; + + if (!dataSource || !symbol) { + continue; + } const symbolProfile = symbolProfiles.find( ({ symbol: symbolProfileSymbol }) => { @@ -145,7 +149,6 @@ export class DataGatheringService { countries, currency, cusip, - dataSource, figi, figiComposite, figiShareClass, @@ -161,17 +164,17 @@ export class DataGatheringService { create: { assetClass, assetSubClass, - countries, - currency, + countries: countries as Prisma.InputJsonValue, + currency: currency as string, cusip, dataSource, figi, figiComposite, figiShareClass, - holdings, + holdings: holdings as Prisma.InputJsonValue, isin, name, - sectors, + sectors: sectors as Prisma.InputJsonValue, symbol, url }, @@ -187,9 +190,15 @@ export class DataGatheringService { name, url, // Keep the stored data if no list is available - countries: isEmpty(countries) ? undefined : countries, - holdings: isEmpty(holdings) ? undefined : holdings, - sectors: isEmpty(sectors) ? undefined : sectors + countries: isEmpty(countries) + ? undefined + : (countries as Prisma.InputJsonValue), + holdings: isEmpty(holdings) + ? undefined + : (holdings as Prisma.InputJsonValue), + sectors: isEmpty(sectors) + ? undefined + : (sectors as Prisma.InputJsonValue) }, where: { dataSource_symbol: { @@ -408,7 +417,7 @@ export class DataGatheringService { jobId: `${getAssetProfileIdentifier({ dataSource, symbol - })}-${format(date, DATE_FORMAT, { in: utc })}` + })}${date ? `-${format(date, DATE_FORMAT, { in: utc })}` : ''}` } }; }) diff --git a/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.service.mock.ts b/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.service.mock.ts index 11b794dfc8..8d0ea87322 100644 --- a/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.service.mock.ts +++ b/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.service.mock.ts @@ -31,7 +31,9 @@ export const PortfolioSnapshotServiceMock = { } }; - PortfolioSnapshotServiceMock.jobsStore.set(opts?.jobId, mockJob); + if (opts?.jobId) { + PortfolioSnapshotServiceMock.jobsStore.set(opts.jobId, mockJob); + } return Promise.resolve(mockJob as Job); },