From 040d6896a3cd5622e78cccdedd8cce2afcf49a31 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sun, 13 Dec 2020 19:27:25 +0100 Subject: add display of logs matching any state --- server/controllers/api/jobs.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts index ed6c94533..1131a44d6 100644 --- a/server/controllers/api/jobs.ts +++ b/server/controllers/api/jobs.ts @@ -12,11 +12,23 @@ import { setDefaultSort } from '../../middlewares' import { paginationValidator } from '../../middlewares/validators' -import { listJobsValidator } from '../../middlewares/validators/jobs' +import { listJobsStateValidator, listJobsValidator } from '../../middlewares/validators/jobs' import { isArray } from '../../helpers/custom-validators/misc' +import { jobStates } from '@server/helpers/custom-validators/jobs' const jobsRouter = express.Router() +jobsRouter.get('/', + authenticate, + ensureUserHasRight(UserRight.MANAGE_JOBS), + paginationValidator, + jobsSortValidator, + setDefaultSort, + setDefaultPagination, + listJobsValidator, + asyncMiddleware(listJobs) +) + jobsRouter.get('/:state', authenticate, ensureUserHasRight(UserRight.MANAGE_JOBS), @@ -25,6 +37,7 @@ jobsRouter.get('/:state', setDefaultSort, setDefaultPagination, listJobsValidator, + listJobsStateValidator, asyncMiddleware(listJobs) ) @@ -37,7 +50,7 @@ export { // --------------------------------------------------------------------------- async function listJobs (req: express.Request, res: express.Response) { - const state = req.params.state as JobState + const state = req.params.state as JobState || jobStates const asc = req.query.sort === 'createdAt' const jobType = req.query.jobType @@ -52,7 +65,11 @@ async function listJobs (req: express.Request, res: express.Response) { const result: ResultList = { total, - data: jobs.map(j => formatJob(j, state)) + data: Array.isArray(state) + ? await Promise.all( + jobs.map(async j => formatJob(j, await j.getState() as JobState)) + ) + : jobs.map(j => formatJob(j, state)) } return res.json(result) } -- cgit v1.2.3