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:
parent
f8802232c6
commit
39ece1b37a
4 changed files with 30 additions and 20 deletions
|
@ -47,6 +47,10 @@ export class I18nService {
|
|||
let value: string | TranslationData = translations;
|
||||
|
||||
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];
|
||||
if (value === undefined) {
|
||||
// Fallback to default locale if key not found
|
||||
|
|
|
@ -74,7 +74,16 @@ type AuthMiddleware = (req: Request, res: Response, next: NextFunction) => void;
|
|||
export default (
|
||||
locationModel: Location,
|
||||
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
|
||||
): Router => {
|
||||
const router = express.Router();
|
||||
|
|
|
@ -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();
|
||||
|
||||
// Rate limiting for location submissions to prevent abuse
|
||||
|
@ -220,7 +224,7 @@ export default (locationModel: Location, profanityFilter: ProfanityFilterService
|
|||
details: {
|
||||
severity: analysis.severity,
|
||||
wordCount: analysis.count,
|
||||
detectedCategories: [...new Set(analysis.matches.map(m => m.category))]
|
||||
detectedCategories: [...new Set(analysis.matches.map((m: any) => m.category))]
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/// <reference path="./types/index.d.ts" />
|
||||
import dotenv from 'dotenv';
|
||||
import express, { Request, Response, NextFunction, Application } from 'express';
|
||||
import cors from 'cors';
|
||||
|
@ -88,23 +89,15 @@ function createFallbackFilter(): FallbackFilter {
|
|||
filterProfanity: (text: string): string => text || '',
|
||||
|
||||
// Database management methods used by admin routes
|
||||
addCustomWord: async (word: string, severity: string, category: string, createdBy?: string) => ({
|
||||
id: null,
|
||||
word: word || null,
|
||||
severity: severity || null,
|
||||
category: category || null,
|
||||
createdBy: createdBy || null,
|
||||
success: false,
|
||||
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'
|
||||
}),
|
||||
addCustomWord: async (): Promise<ProfanityWord> => {
|
||||
throw new Error('Profanity filter not available - please check server configuration');
|
||||
},
|
||||
removeCustomWord: async (): Promise<{ deleted: boolean; changes: number }> => {
|
||||
throw new Error('Profanity filter not available - please check server configuration');
|
||||
},
|
||||
updateCustomWord: async (): Promise<ProfanityWord> => {
|
||||
throw new Error('Profanity filter not available - please check server configuration');
|
||||
},
|
||||
getCustomWords: async (): Promise<ProfanityWord[]> => [],
|
||||
loadCustomWords: async (): Promise<void> => {},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue