Fix TypeScript compilation errors and type safety issues

- Fix i18n string indexing by adding proper type checking
- Add Express Request type extensions for locale and t properties
- Fix ProfanityFilter interface mismatches with proper return types
- Update route signatures to accept union types for fallback filter
- Resolve all TypeScript compilation errors while maintaining functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Code 2025-07-07 21:23:36 -04:00
parent f8802232c6
commit 39ece1b37a
4 changed files with 30 additions and 20 deletions

View file

@ -47,6 +47,10 @@ export class I18nService {
let value: string | TranslationData = translations; let value: string | TranslationData = translations;
for (const key of keys) { for (const key of keys) {
if (typeof value === 'string') {
// If we hit a string before traversing all keys, the path is invalid
break;
}
value = value?.[key]; value = value?.[key];
if (value === undefined) { if (value === undefined) {
// Fallback to default locale if key not found // Fallback to default locale if key not found

View file

@ -74,7 +74,16 @@ type AuthMiddleware = (req: Request, res: Response, next: NextFunction) => void;
export default ( export default (
locationModel: Location, locationModel: Location,
profanityWordModel: ProfanityWord, profanityWordModel: ProfanityWord,
profanityFilter: ProfanityFilterService, profanityFilter: ProfanityFilterService | {
containsProfanity(): boolean;
analyzeProfanity(text: string): any;
filterProfanity(text: string): string;
addCustomWord(word: string, severity: string, category: string, createdBy?: string): Promise<any>;
removeCustomWord(wordId: number): Promise<any>;
updateCustomWord(wordId: number, updates: any): Promise<any>;
getCustomWords(): Promise<any[]>;
loadCustomWords(): Promise<void>;
},
authenticateAdmin: AuthMiddleware authenticateAdmin: AuthMiddleware
): Router => { ): Router => {
const router = express.Router(); const router = express.Router();

View file

@ -14,7 +14,11 @@ interface LocationPostRequest extends Request {
} }
export default (locationModel: Location, profanityFilter: ProfanityFilterService): Router => { export default (locationModel: Location, profanityFilter: ProfanityFilterService | {
containsProfanity(): boolean;
analyzeProfanity(text: string): any;
filterProfanity(text: string): string;
}): Router => {
const router = express.Router(); const router = express.Router();
// Rate limiting for location submissions to prevent abuse // Rate limiting for location submissions to prevent abuse
@ -220,7 +224,7 @@ export default (locationModel: Location, profanityFilter: ProfanityFilterService
details: { details: {
severity: analysis.severity, severity: analysis.severity,
wordCount: analysis.count, wordCount: analysis.count,
detectedCategories: [...new Set(analysis.matches.map(m => m.category))] detectedCategories: [...new Set(analysis.matches.map((m: any) => m.category))]
} }
}); });
return; return;

View file

@ -1,3 +1,4 @@
/// <reference path="./types/index.d.ts" />
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import express, { Request, Response, NextFunction, Application } from 'express'; import express, { Request, Response, NextFunction, Application } from 'express';
import cors from 'cors'; import cors from 'cors';
@ -88,23 +89,15 @@ function createFallbackFilter(): FallbackFilter {
filterProfanity: (text: string): string => text || '', filterProfanity: (text: string): string => text || '',
// Database management methods used by admin routes // Database management methods used by admin routes
addCustomWord: async (word: string, severity: string, category: string, createdBy?: string) => ({ addCustomWord: async (): Promise<ProfanityWord> => {
id: null, throw new Error('Profanity filter not available - please check server configuration');
word: word || null, },
severity: severity || null, removeCustomWord: async (): Promise<{ deleted: boolean; changes: number }> => {
category: category || null, throw new Error('Profanity filter not available - please check server configuration');
createdBy: createdBy || null, },
success: false, updateCustomWord: async (): Promise<ProfanityWord> => {
error: 'Profanity filter not available - please check server configuration' throw new Error('Profanity filter not available - please check server configuration');
}), },
removeCustomWord: async () => ({
success: false,
error: 'Profanity filter not available - please check server configuration'
}),
updateCustomWord: async () => ({
success: false,
error: 'Profanity filter not available - please check server configuration'
}),
getCustomWords: async (): Promise<ProfanityWord[]> => [], getCustomWords: async (): Promise<ProfanityWord[]> => [],
loadCustomWords: async (): Promise<void> => {}, loadCustomWords: async (): Promise<void> => {},