fix(#65): GET /schedules returns 400 for unknown status query param
This commit is contained in:
parent
548c2ab8a4
commit
75c23448b4
1 changed files with 5 additions and 0 deletions
|
|
@ -30,10 +30,15 @@ function rowToJson(r) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ALLOWED_STATUS_FILTER = new Set(['all', 'upcoming', 'past']);
|
||||||
|
|
||||||
// GET /api/v1/schedules?status=upcoming|past|all
|
// GET /api/v1/schedules?status=upcoming|past|all
|
||||||
router.get('/', async (req, res, next) => {
|
router.get('/', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const status = (req.query.status || 'all').toLowerCase();
|
const status = (req.query.status || 'all').toLowerCase();
|
||||||
|
if (!ALLOWED_STATUS_FILTER.has(status)) {
|
||||||
|
return res.status(400).json({ error: `status must be one of: ${[...ALLOWED_STATUS_FILTER].join(', ')}` });
|
||||||
|
}
|
||||||
let where = 'TRUE';
|
let where = 'TRUE';
|
||||||
if (status === 'upcoming') where = `(s.status IN ('pending','running') OR s.end_at >= NOW() - INTERVAL '1 hour')`;
|
if (status === 'upcoming') where = `(s.status IN ('pending','running') OR s.end_at >= NOW() - INTERVAL '1 hour')`;
|
||||||
else if (status === 'past') where = `s.status IN ('completed','failed','cancelled') AND s.end_at < NOW()`;
|
else if (status === 'past') where = `s.status IN ('completed','failed','cancelled') AND s.end_at < NOW()`;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue