Skip to content

Commit 1db8b0f

Browse files
committed
rikkinäisten otsikoiden etsimis-endpoint
1 parent 7ab6e08 commit 1db8b0f

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

backend/src/app.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type { StatuteKey } from './types/statute.js';
1818
import { getRecentLogs, pushLog } from './util/logBuffer.js';
1919
import { printSyncSummary } from "./util/syncResults.js";
2020
import { 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

2323
const app = express()
2424
const __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)
273272
app.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+
455497
app.get('/favicon.ico', (request: express.Request, response: express.Response): void => {
456498
response.status(204).end();
457499
})

backend/src/db/db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,4 @@ async function addStatusRow(data: object, updating: boolean = false): Promise<vo
510510
}
511511
}
512512

513-
export { query, setPool, closePool, createTables, dropTables, dbIsReady, fillDb, dbIsUpToDate, setupTestDatabase, clearStatusRows, addStatusRow, dropJudgmentsTables, createJudgmentsTables, deleteStatutesByYear, normalizeStatuteTitlesByYear };
513+
export { query, pool, setPool, closePool, createTables, dropTables, dbIsReady, fillDb, dbIsUpToDate, setupTestDatabase, clearStatusRows, addStatusRow, dropJudgmentsTables, createJudgmentsTables, deleteStatutesByYear, normalizeStatuteTitlesByYear };

0 commit comments

Comments
 (0)