]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/jobs.ts
Add beautiful loading bar
[github/Chocobozzz/PeerTube.git] / server / controllers / api / jobs.ts
CommitLineData
5cd80545
C
1import * as express from 'express'
2import { asyncMiddleware, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares'
3import { paginationValidator } from '../../middlewares/validators/pagination'
4import { database as db } from '../../initializers'
5import { getFormattedObjects } from '../../helpers/utils'
6import { authenticate } from '../../middlewares/oauth'
7import { ensureUserHasRight } from '../../middlewares/user-right'
8import { UserRight } from '../../../shared/models/users/user-right.enum'
9
10const jobsRouter = express.Router()
11
12jobsRouter.get('/',
13 authenticate,
14 ensureUserHasRight(UserRight.MANAGE_JOBS),
15 paginationValidator,
16 jobsSortValidator,
17 setJobsSort,
18 setPagination,
19 asyncMiddleware(listJobs)
20)
21
22// ---------------------------------------------------------------------------
23
24export {
25 jobsRouter
26}
27
28// ---------------------------------------------------------------------------
29
30async 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}