diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/jobs.ts | 34 |
2 files changed, 36 insertions, 0 deletions
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' | |||
7 | import { serverRouter } from './server' | 7 | import { serverRouter } from './server' |
8 | import { usersRouter } from './users' | 8 | import { usersRouter } from './users' |
9 | import { videosRouter } from './videos' | 9 | import { videosRouter } from './videos' |
10 | import { jobsRouter } from './jobs' | ||
10 | 11 | ||
11 | const apiRouter = express.Router() | 12 | const apiRouter = express.Router() |
12 | 13 | ||
@@ -15,6 +16,7 @@ apiRouter.use('/oauth-clients', oauthClientsRouter) | |||
15 | apiRouter.use('/config', configRouter) | 16 | apiRouter.use('/config', configRouter) |
16 | apiRouter.use('/users', usersRouter) | 17 | apiRouter.use('/users', usersRouter) |
17 | apiRouter.use('/videos', videosRouter) | 18 | apiRouter.use('/videos', videosRouter) |
19 | apiRouter.use('/jobs', jobsRouter) | ||
18 | apiRouter.use('/ping', pong) | 20 | apiRouter.use('/ping', pong) |
19 | apiRouter.use('/*', badRequest) | 21 | apiRouter.use('/*', badRequest) |
20 | 22 | ||
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { asyncMiddleware, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' | ||
3 | import { paginationValidator } from '../../middlewares/validators/pagination' | ||
4 | import { database as db } from '../../initializers' | ||
5 | import { getFormattedObjects } from '../../helpers/utils' | ||
6 | import { authenticate } from '../../middlewares/oauth' | ||
7 | import { ensureUserHasRight } from '../../middlewares/user-right' | ||
8 | import { UserRight } from '../../../shared/models/users/user-right.enum' | ||
9 | |||
10 | const jobsRouter = express.Router() | ||
11 | |||
12 | jobsRouter.get('/', | ||
13 | authenticate, | ||
14 | ensureUserHasRight(UserRight.MANAGE_JOBS), | ||
15 | paginationValidator, | ||
16 | jobsSortValidator, | ||
17 | setJobsSort, | ||
18 | setPagination, | ||
19 | asyncMiddleware(listJobs) | ||
20 | ) | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | export { | ||
25 | jobsRouter | ||
26 | } | ||
27 | |||
28 | // --------------------------------------------------------------------------- | ||
29 | |||
30 | async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
31 | const resultList = await db.Job.listForApi(req.query.start, req.query.count, req.query.sort) | ||
32 | |||
33 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | ||
34 | } | ||