Skip to content

Latest commit

 

History

History
351 lines (285 loc) · 9.13 KB

File metadata and controls

351 lines (285 loc) · 9.13 KB

TypeScript Error Fixes for NestJS Quest Service

Summary of Fixes Applied

1. ✅ Fixed Analytics Module

  • Added missing class-validator imports to all DTOs
  • Added missing TypeORM imports to all entities
  • Created src/analytics/dto/index.ts barrel export file
  • Fixed duplicate PuzzleDifficulty enum exports

2. ✅ Installed Missing Type Definitions

npm install --save-dev @types/csv-parser @types/xml2js @types/passport-google-oauth20 @types/nodemailer

3. 🔧 Remaining Fixes Needed

A. Fix Duplicate Identifier Errors

File: src/puzzles/ai-assistant/hint-progression.service.ts

  • Issue: Duplicate Injectable import (lines 1 and 172)
  • Fix: Remove duplicate code at line 172 onwards

File: src/puzzles/collection.service.ts

  • Issue: Duplicate In import from TypeORM (lines 3 and 154)
  • Fix: Keep only one import statement

File: src/logging/middleware/logging.middleware.ts

  • Issue: Duplicate NextFunction import
  • Fix: Import from express only once: import { Request, Response, NextFunction } from 'express';

B. Fix Namespace Errors (TS2709)

All instances of using namespaces as types need to be fixed by importing the actual type:

ConfigService namespace errors:

// WRONG:
constructor(private configService: ConfigService) {}

// CORRECT:
import { ConfigService } from '@nestjs/config';
constructor(private readonly configService: ConfigService<any>) {}

ConfigType namespace errors:

// WRONG:
@Inject(cacheConfig.KEY) private config: ConfigType

// CORRECT:
import { ConfigType } from '@nestjs/config';
@Inject(cacheConfig.KEY) private config: ConfigType<typeof cacheConfig>

Other namespace fixes needed:

  • HealthCheckService → Import from @nestjs/terminus
  • TypeOrmHealthIndicator → Import from @nestjs/terminus
  • MemoryHealthIndicator → Import from @nestjs/terminus
  • DiskHealthIndicator → Import from @nestjs/terminus
  • Counter, Gauge, Histogram → Import from prom-client
  • Transporter → Import from nodemailer
  • ValidationArguments, ValidationOptions → Import from class-validator
  • Cache → Import from cache-manager

C. Fix Request/Response Type Issues

File: src/logging/middleware/logging.middleware.ts

import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';

@Injectable()
export class LoggingMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    // Access properties correctly
    const userAgent = req.get('user-agent');
    const ip = req.ip;
    
    // Wrap res.end properly
    const originalEnd = res.end.bind(res);
    res.end = function(chunk?: any, encoding?: any, callback?: any) {
      // Log response
      return originalEnd(chunk, encoding, callback);
    };
    
    next();
  }
}

File: src/user-progress/user-collection-progress.controller.ts

// Add interface for authenticated request
import { Request } from 'express';

interface RequestWithUser extends Request {
  user: {
    id: string;
    // other user properties
  };
}

// Use in controller
@Get()
async getProgress(@Req() req: RequestWithUser) {
  const userId = req.user.id;
  // ...
}

D. Create Missing Files

File: src/puzzles/ai-assistant/learning-path.service.ts

import { Injectable } from '@nestjs/common';

export interface LearningPath {
  currentLevel: string;
  recommendedPuzzles: string[];
  skillGaps: string[];
  progressPercentage: number;
}

@Injectable()
export class LearningPathService {
  async generateLearningPath(userId: string, puzzleHistory: any[]): Promise<LearningPath> {
    // Implementation
    return {
      currentLevel: 'intermediate',
      recommendedPuzzles: [],
      skillGaps: [],
      progressPercentage: 0,
    };
  }
}

File: src/common/pipes/parse-array-int.pipe.ts

import { PipeTransform, Injectable, BadRequestException } from '@nestjs/common';

@Injectable()
export class ParseArrayIntPipe implements PipeTransform<string, number[]> {
  transform(value: string): number[] {
    if (!value) return [];
    
    const arr = value.split(',').map(v => parseInt(v.trim(), 10));
    
    if (arr.some(isNaN)) {
      throw new BadRequestException('Invalid array of integers');
    }
    
    return arr;
  }
}

E. Fix Missing Type Definitions

File: src/puzzles/ai-assistant/ai-assistant.service.ts

// Add missing interfaces
export interface PuzzleAnalysis {
  difficulty: string;
  concepts: string[];
  estimatedTime: number;
}

export interface HintRequestDto {
  puzzleId: string;
  userId: string;
  currentProgress: any;
}

export interface Hint {
  level: number;
  content: string;
  type: string;
}

export interface ThinkingProcessRequestDto {
  puzzleId: string;
  userId: string;
}

File: src/puzzles/ai-assistant/strategy-explainer.service.ts

// Add missing interface
export interface Strategy {
  name: string;
  description: string;
  steps: string[];
  difficulty: string;
}

F. Fix Entity Relationship Errors

Files with missing entity imports:

  • src/content/comment.entity.ts - Import Content from correct location
  • src/content/contents.entity.ts - Import User, Category, etc.
  • src/puzzles/entities/category.entity.ts - Fix categoriescategory
  • src/puzzles/entities/collection.entity.ts - Fix collectionscompletions

G. Fix Type Mismatches

File: src/auth/auth.module.ts

// Fix JWT expiration time type
JwtModule.register({
  secret: process.env.JWT_SECRET,
  signOptions: { expiresIn: '1h' }, // Use string, not number
}),

File: src/leaderboard/leaderboard.service.ts

// Fix order syntax for TypeORM
const entries = await this.leaderboardRepository.find({
  order: {
    score: 'DESC',
    userId: 'ASC',
  },
});

File: src/puzzle-editor/services/puzzle-editor.service.ts

// Fix EditorMetadata type
const metadata: EditorMetadata = {
  version: '1.0',
  lastSaved: new Date(),
  lastModifiedBy: userId,
  autosaveEnabled: true,
  autosaveInterval: 30000,
};

H. Fix Parameter Errors

File: src/puzzle-editor/controllers/community-submission.controller.ts

// Fix parameter order - required parameters must come before optional
async submitPuzzle(
  @Body() dto: SubmitPuzzleDto,
  @Req() req: Request,
  @Query('draft') draft?: boolean, // Optional parameter last
) {
  // ...
}

File: src/procedural-generation/analytics.service.ts

// Fix read-only property assignment
// Instead of: this.analytics = newValue;
// Use a method or make property mutable
private analyticsData: AnalyticsData;

updateAnalytics(data: AnalyticsData) {
  this.analyticsData = data;
}

I. Fix Missing Constants and Enums

File: src/game-engine/services/puzzle-engine.service.ts

// Add missing constant
const SESSION_COMBO_WINDOW_MILLIS = 5 * 60 * 1000; // 5 minutes

// Add missing imports
import { UserPuzzleCompletion } from '../entities/user-puzzle-completion.entity';
import { UserStats } from '../entities/user-stats.entity';
import { User } from '../../users/entities/user.entity';
import { Puzzle } from '../../puzzles/entities/puzzle.entity';

File: src/procedural-generation/algorithms.ts

// Define missing variable
const complexity = calculateComplexity(puzzle);

J. Fix Module Import Errors

File: src/leaderboard/leaderboard.module.ts

// CacheModule is deprecated in NestJS 10
// Use CacheModule from @nestjs/cache-manager instead
import { CacheModule } from '@nestjs/cache-manager';

File: src/leaderboard/leaderboard.service.ts

// Update CACHE_MANAGER import
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Cache } from 'cache-manager';

constructor(
  @Inject(CACHE_MANAGER) private cacheManager: Cache,
) {}

File: src/cache/cache.module.ts

// Install and use correct Redis module
// npm install @nestjs/cache-manager cache-manager
// npm install cache-manager-redis-store
import { CacheModule } from '@nestjs/cache-manager';
import * as redisStore from 'cache-manager-redis-store';

4. Quick Fix Commands

# Install missing dependencies
npm install @nestjs/cache-manager cache-manager cache-manager-redis-store
npm install --save-dev @types/cache-manager

# Install missing packages
npm install ioredis
npm install --save-dev @types/ioredis

Priority Order for Fixes

  1. COMPLETED: Analytics module (DTOs and entities)
  2. COMPLETED: Type definitions installation
  3. HIGH: Fix duplicate identifier errors
  4. HIGH: Create missing service files (learning-path.service.ts)
  5. HIGH: Fix namespace errors (ConfigService, ConfigType, etc.)
  6. MEDIUM: Fix Request/Response middleware types
  7. MEDIUM: Fix entity relationship imports
  8. LOW: Fix type mismatches and parameter ordering
  9. LOW: Add missing constants and helper functions

Testing After Fixes

# Run TypeScript compiler check
npx tsc --noEmit

# Run tests
npm test

# Build the project
npm run build