diff options
Diffstat (limited to 'server/controllers/api/jobs.ts')
-rw-r--r-- | server/controllers/api/jobs.ts | 34 |
1 files changed, 34 insertions, 0 deletions
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 | } | ||