Browse Source

Task/improve type safety for unassigned variables in API (#7755)

* fix(api): resolve type errors in src/app

* fix(api): resolve type errors in src/services

* fix(api): update log level type

* fix(api): reformat files
pull/7757/head^2
Kenrick Tandrian 2 weeks ago
committed by GitHub
parent
commit
94aa4793fe
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      apps/api/src/app/activities/activities.controller.ts
  2. 3
      apps/api/src/app/activities/activities.service.ts
  3. 2
      apps/api/src/app/admin/admin.controller.ts
  4. 2
      apps/api/src/app/admin/admin.service.ts
  5. 4
      apps/api/src/app/endpoints/mcp/mcp.controller.ts
  6. 4
      apps/api/src/app/export/export.controller.ts
  7. 6
      apps/api/src/app/import/import.service.ts
  8. 5
      apps/api/src/app/info/info.service.ts
  9. 2
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  10. 7
      apps/api/src/app/portfolio/portfolio.service.ts
  11. 2
      apps/api/src/main.ts
  12. 8
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts
  13. 2
      apps/api/src/services/fetch/fetch.service.ts
  14. 2
      apps/api/src/services/prisma/prisma.service.ts
  15. 2
      apps/api/src/services/queues/data-gathering/data-gathering.processor.ts

8
apps/api/src/app/activities/activities.controller.ts

@ -66,8 +66,8 @@ export class ActivitiesController {
tags tags
}: ActivitiesFilterDto }: ActivitiesFilterDto
): Promise<number> { ): Promise<number> {
let endDate: Date; let endDate: Date | undefined;
let startDate: Date; let startDate: Date | undefined;
if (range) { if (range) {
({ endDate, startDate } = getIntervalFromDateRange({ ({ endDate, startDate } = getIntervalFromDateRange({
@ -139,8 +139,8 @@ export class ActivitiesController {
take take
}: GetActivitiesDto }: GetActivitiesDto
): Promise<ActivitiesResponse> { ): Promise<ActivitiesResponse> {
let endDate: Date; let endDate: Date | undefined;
let startDate: Date; let startDate: Date | undefined;
if (range) { if (range) {
({ endDate, startDate } = getIntervalFromDateRange({ ({ endDate, startDate } = getIntervalFromDateRange({

3
apps/api/src/app/activities/activities.service.ts

@ -193,7 +193,8 @@ export class ActivitiesService {
userId: data.userId userId: data.userId
}); });
let account: Prisma.AccountCreateNestedOneWithoutActivitiesInput; let account:
Prisma.AccountCreateNestedOneWithoutActivitiesInput | undefined;
if (data.accountId) { if (data.accountId) {
account = { account = {

2
apps/api/src/app/admin/admin.controller.ts

@ -186,7 +186,7 @@ export class AdminController {
@Param('symbol') symbol: string, @Param('symbol') symbol: string,
@Query('range') dateRange: DateRange @Query('range') dateRange: DateRange
): Promise<void> { ): Promise<void> {
let date: Date; let date: Date | undefined;
if (dateRange) { if (dateRange) {
const { startDate } = getIntervalFromDateRange({ dateRange }); const { startDate } = getIntervalFromDateRange({ dateRange });

2
apps/api/src/app/admin/admin.service.ts

@ -659,7 +659,7 @@ export class AdminService {
} }
private async countUsersWithAnalytics() { private async countUsersWithAnalytics() {
let where: Prisma.UserWhereInput; let where: Prisma.UserWhereInput | undefined;
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
where = { where = {

4
apps/api/src/app/endpoints/mcp/mcp.controller.ts

@ -99,8 +99,8 @@ export class GhostfolioMcpController {
take take
}: z.infer<typeof GET_ACTIVITIES_PARAMETERS> }: z.infer<typeof GET_ACTIVITIES_PARAMETERS>
) { ) {
let endDate: Date; let endDate: Date | undefined;
let startDate: Date; let startDate: Date | undefined;
if (range) { if (range) {
({ endDate, startDate } = getIntervalFromDateRange({ ({ endDate, startDate } = getIntervalFromDateRange({

4
apps/api/src/app/export/export.controller.ts

@ -45,8 +45,8 @@ export class ExportController {
tags tags
}: GetExportDto }: GetExportDto
): Promise<ExportResponse> { ): Promise<ExportResponse> {
let endDate: Date; let endDate: Date | undefined;
let startDate: Date; let startDate: Date | undefined;
if (range) { if (range) {
({ endDate, startDate } = getIntervalFromDateRange({ ({ endDate, startDate } = getIntervalFromDateRange({

6
apps/api/src/app/import/import.service.ts

@ -395,7 +395,7 @@ export class ImportService {
if (!isDryRun) { if (!isDryRun) {
const existingTag = await this.tagService.getTag({ id: tag.id }); const existingTag = await this.tagService.getTag({ id: tag.id });
let oldTagId: string; let oldTagId: string | undefined;
if (existingTag) { if (existingTag) {
oldTagId = tag.id; oldTagId = tag.id;
@ -509,7 +509,7 @@ export class ImportService {
'tags' 'tags'
]); ]);
let oldAccountId: string; let oldAccountId: string | undefined;
const platformId = const platformId =
platformIdMapping[account.platformId] ?? account.platformId; platformIdMapping[account.platformId] ?? account.platformId;
@ -596,7 +596,7 @@ export class ImportService {
]); ]);
for (const assetProfileWithMarketData of assetProfilesWithMarketDataDto) { for (const assetProfileWithMarketData of assetProfilesWithMarketDataDto) {
let assetProfileToCreate: Prisma.SymbolProfileCreateInput; let assetProfileToCreate: Prisma.SymbolProfileCreateInput | undefined;
let symbol = assetProfileWithMarketData.symbol; let symbol = assetProfileWithMarketData.symbol;
// Check if there is any existing asset profile // Check if there is any existing asset profile

5
apps/api/src/app/info/info.service.ts

@ -47,8 +47,9 @@ export class InfoService {
public async get(): Promise<InfoItem> { public async get(): Promise<InfoItem> {
const info: Partial<InfoItem> = {}; const info: Partial<InfoItem> = {};
let isReadOnlyMode: boolean; let isReadOnlyMode: boolean | undefined;
let latestFearAndGreedStocksMarketDataPromise: Promise<MarketData>; let latestFearAndGreedStocksMarketDataPromise:
Promise<MarketData> | undefined;
const globalPermissions: string[] = []; const globalPermissions: string[] = [];

2
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -1166,7 +1166,7 @@ export abstract class PortfolioCalculator {
private async initialize(attempt = 1) { private async initialize(attempt = 1) {
const startTimeTotal = performance.now(); const startTimeTotal = performance.now();
let cachedPortfolioSnapshot: PortfolioSnapshot; let cachedPortfolioSnapshot: PortfolioSnapshot | undefined;
let isCachedPortfolioSnapshotExpired = false; let isCachedPortfolioSnapshotExpired = false;
const portfolioSnapshotKey = this.redisCacheService.getPortfolioSnapshotKey( const portfolioSnapshotKey = this.redisCacheService.getPortfolioSnapshotKey(
{ {

7
apps/api/src/app/portfolio/portfolio.service.ts

@ -569,7 +569,10 @@ export class PortfolioService {
}); });
} }
let streaks: PortfolioInvestmentsResponse['streaks']; let streaks: PortfolioInvestmentsResponse['streaks'] = {
currentStreak: 0,
longestStreak: 0
};
if (savingsRate) { if (savingsRate) {
streaks = this.getStreaks({ streaks = this.getStreaks({
@ -853,7 +856,7 @@ export class PortfolioService {
({ markets, marketsAdvanced } = this.getAggregatedMarkets(holdings)); ({ markets, marketsAdvanced } = this.getAggregatedMarkets(holdings));
} }
let summary: PortfolioSummary; let summary: PortfolioSummary | undefined;
if (withSummary) { if (withSummary) {
summary = await this.getSummary({ summary = await this.getSummary({

2
apps/api/src/main.ts

@ -46,7 +46,7 @@ async function bootstrap() {
const configApp = await NestFactory.create(AppModule); const configApp = await NestFactory.create(AppModule);
const configService = configApp.get<ConfigService>(ConfigService); const configService = configApp.get<ConfigService>(ConfigService);
let customLogLevels: LogLevel[]; let customLogLevels: LogLevel[] | undefined;
try { try {
customLogLevels = JSON.parse( customLogLevels = JSON.parse(

8
apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

@ -726,11 +726,11 @@ export class FinancialModelingPrepService
} }
private parseAssetClass(profile: any): { private parseAssetClass(profile: any): {
assetClass: AssetClass; assetClass: AssetClass | undefined;
assetSubClass: AssetSubClass; assetSubClass: AssetSubClass | undefined;
} { } {
let assetClass: AssetClass; let assetClass: AssetClass | undefined;
let assetSubClass: AssetSubClass; let assetSubClass: AssetSubClass | undefined;
if (profile) { if (profile) {
if (profile.isEtf) { if (profile.isEtf) {

2
apps/api/src/services/fetch/fetch.service.ts

@ -156,7 +156,7 @@ export class FetchService implements OnModuleInit {
text text
]; ];
let rejectedBody: string; let rejectedBody: string | undefined;
for (const candidate of candidates) { for (const candidate of candidates) {
if (typeof candidate !== 'string') { if (typeof candidate !== 'string') {

2
apps/api/src/services/prisma/prisma.service.ts

@ -21,7 +21,7 @@ export class PrismaService
connectionString: configService.get<string>('DATABASE_URL') connectionString: configService.get<string>('DATABASE_URL')
}); });
let customLogLevels: LogLevel[]; let customLogLevels: LogLevel[] | undefined;
try { try {
customLogLevels = JSON.parse( customLogLevels = JSON.parse(

2
apps/api/src/services/queues/data-gathering/data-gathering.processor.ts

@ -119,7 +119,7 @@ export class DataGatheringProcessor {
const data: Prisma.MarketDataUpdateInput[] = []; const data: Prisma.MarketDataUpdateInput[] = [];
const startOfUtcDateOfToday = getStartOfUtcDate(new Date()); const startOfUtcDateOfToday = getStartOfUtcDate(new Date());
let lastMarketPrice: number; let lastMarketPrice: number | undefined;
while (isBefore(currentDate, startOfUtcDateOfToday)) { while (isBefore(currentDate, startOfUtcDateOfToday)) {
const marketPriceOfDataProvider = const marketPriceOfDataProvider =

Loading…
Cancel
Save