Add sentence_de filter to GET /api/questions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-21 15:09:08 +02:00
parent b4de0b98c3
commit 15fa315b3f

View File

@@ -7,10 +7,12 @@ const STATUS_TIMESTAMP = { published: 'published_at', blocked: 'blocked_at' };
// GET /api/questions
router.get('/', async (req, res, next) => {
try {
const { status, limit = 50, offset = 0 } = req.query;
const { status, sentence_de, limit = 50, offset = 0 } = req.query;
const params = [Math.min(parseInt(limit), 500), parseInt(offset)];
const where = status ? `WHERE status = $3` : '';
if (status) params.push(status);
const conditions = [];
if (status) { conditions.push(`status = $${params.length + 1}`); params.push(status); }
if (sentence_de) { conditions.push(`lower(sentence_de) = lower($${params.length + 1})`); params.push(sentence_de); }
const where = conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
const result = await query(
`SELECT * FROM questions ${where} ORDER BY created_at DESC LIMIT $1 OFFSET $2`,
params