Add sentence_de filter to GET /api/questions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,10 +7,12 @@ const STATUS_TIMESTAMP = { published: 'published_at', blocked: 'blocked_at' };
|
|||||||
// GET /api/questions
|
// GET /api/questions
|
||||||
router.get('/', async (req, res, next) => {
|
router.get('/', async (req, res, next) => {
|
||||||
try {
|
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 params = [Math.min(parseInt(limit), 500), parseInt(offset)];
|
||||||
const where = status ? `WHERE status = $3` : '';
|
const conditions = [];
|
||||||
if (status) params.push(status);
|
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(
|
const result = await query(
|
||||||
`SELECT * FROM questions ${where} ORDER BY created_at DESC LIMIT $1 OFFSET $2`,
|
`SELECT * FROM questions ${where} ORDER BY created_at DESC LIMIT $1 OFFSET $2`,
|
||||||
params
|
params
|
||||||
|
|||||||
Reference in New Issue
Block a user