From 5cd80545422bba855cc9a730a2e13cc9d982c34b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 30 Nov 2017 10:51:13 +0100 Subject: Add ability to list jobs --- server/controllers/api/index.ts | 2 ++ server/controllers/api/jobs.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 server/controllers/api/jobs.ts (limited to 'server/controllers/api') diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index b00fb7467..737ea4602 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts @@ -7,6 +7,7 @@ import { configRouter } from './config' import { serverRouter } from './server' import { usersRouter } from './users' import { videosRouter } from './videos' +import { jobsRouter } from './jobs' const apiRouter = express.Router() @@ -15,6 +16,7 @@ apiRouter.use('/oauth-clients', oauthClientsRouter) apiRouter.use('/config', configRouter) apiRouter.use('/users', usersRouter) apiRouter.use('/videos', videosRouter) +apiRouter.use('/jobs', jobsRouter) apiRouter.use('/ping', pong) apiRouter.use('/*', badRequest) diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts new file mode 100644 index 000000000..f6fbff369 --- /dev/null +++ b/server/controllers/api/jobs.ts @@ -0,0 +1,34 @@ +import * as express from 'express' +import { asyncMiddleware, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' +import { paginationValidator } from '../../middlewares/validators/pagination' +import { database as db } from '../../initializers' +import { getFormattedObjects } from '../../helpers/utils' +import { authenticate } from '../../middlewares/oauth' +import { ensureUserHasRight } from '../../middlewares/user-right' +import { UserRight } from '../../../shared/models/users/user-right.enum' + +const jobsRouter = express.Router() + +jobsRouter.get('/', + authenticate, + ensureUserHasRight(UserRight.MANAGE_JOBS), + paginationValidator, + jobsSortValidator, + setJobsSort, + setPagination, + asyncMiddleware(listJobs) +) + +// --------------------------------------------------------------------------- + +export { + jobsRouter +} + +// --------------------------------------------------------------------------- + +async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) { + const resultList = await db.Job.listForApi(req.query.start, req.query.count, req.query.sort) + + return res.json(getFormattedObjects(resultList.data, resultList.total)) +} -- cgit v1.2.3