@@ -18,7 +18,7 @@ import type { StatuteKey } from './types/statute.js';
1818import { getRecentLogs , pushLog } from './util/logBuffer.js' ;
1919import { printSyncSummary } from "./util/syncResults.js" ;
2020import { deleteCollection , syncStatutes , syncJudgments , upsertJudgmentByUuid , upsertStatuteByUuid , SyncResult } from './search.js' ;
21- import { query } from './db/db.js' ;
21+ import { query , pool } from './db/db.js' ;
2222
2323const app = express ( )
2424const __filename = fileURLToPath ( import . meta. url ) ;
@@ -269,7 +269,6 @@ app.get('/api/status/latest', verifyAdminToken, async (req: express.Request, res
269269 }
270270} ) ;
271271
272- // Return recent application logs (from in-memory buffer)
273272app . get ( '/api/logs' , ( req : express . Request , res : express . Response ) : void => {
274273 const limitParam = req . query . limit ? parseInt ( req . query . limit as string , 10 ) : 20 ;
275274 const logs = getRecentLogs ( limitParam ) ;
@@ -452,6 +451,49 @@ app.post('/api/rebuild-typesense', verifyAdminToken, async (req: express.Request
452451 }
453452} ) ;
454453
454+ app . get ( '/api/admin/check-title-issues' , verifyAdminToken , async ( req : express . Request , res : express . Response ) : Promise < void > => {
455+ try {
456+ const client = await pool . connect ( ) ;
457+
458+ const yearQuery = await client . query ( `
459+ SELECT
460+ year,
461+ COUNT(*) as potentially_wrong_count
462+ FROM statutes
463+ WHERE
464+ (
465+ (title LIKE '%§:n' OR title LIKE '%§:n %')
466+ AND (title LIKE '%momentissa%' OR title LIKE '%kohdassa%' OR title LIKE '%tarkoitetuista%')
467+ )
468+ GROUP BY year
469+ HAVING COUNT(*) > 0
470+ ORDER BY year DESC
471+ ` ) ;
472+
473+ const exampleQuery = await client . query ( `
474+ SELECT year, number, language, title
475+ FROM statutes
476+ WHERE
477+ (title LIKE '%§:n' OR title LIKE '%§:n %')
478+ AND (title LIKE '%momentissa%' OR title LIKE '%kohdassa%' OR title LIKE '%tarkoitetuista%')
479+ ORDER BY year DESC, number
480+ LIMIT 10
481+ ` ) ;
482+
483+ client . release ( ) ;
484+
485+ res . status ( 200 ) . json ( {
486+ yearsWithIssues : yearQuery . rows ,
487+ exampleStatutes : exampleQuery . rows ,
488+ totalYears : yearQuery . rows . length
489+ } ) ;
490+ } catch ( error ) {
491+ console . error ( 'Check title issues endpoint error:' , error ) ;
492+ Sentry . captureException ( error ) ;
493+ res . status ( 500 ) . json ( { error : 'Failed to check title issues' } ) ;
494+ }
495+ } ) ;
496+
455497app . get ( '/favicon.ico' , ( request : express . Request , response : express . Response ) : void => {
456498 response . status ( 204 ) . end ( ) ;
457499} )
0 commit comments