2017-11-30 10:51:13 +01:00
|
|
|
import * as express from 'express'
|
2017-12-12 17:53:50 +01:00
|
|
|
import { UserRight } from '../../../shared/models/users'
|
2017-12-28 11:16:08 +01:00
|
|
|
import { getFormattedObjects } from '../../helpers/utils'
|
2018-01-18 10:53:54 +01:00
|
|
|
import {
|
|
|
|
asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setDefaultPagination,
|
|
|
|
setDefaultSort
|
|
|
|
} from '../../middlewares'
|
2017-12-12 17:53:50 +01:00
|
|
|
import { paginationValidator } from '../../middlewares/validators'
|
|
|
|
import { JobModel } from '../../models/job/job'
|
2017-11-30 10:51:13 +01:00
|
|
|
|
|
|
|
const jobsRouter = express.Router()
|
|
|
|
|
|
|
|
jobsRouter.get('/',
|
|
|
|
authenticate,
|
|
|
|
ensureUserHasRight(UserRight.MANAGE_JOBS),
|
|
|
|
paginationValidator,
|
|
|
|
jobsSortValidator,
|
2018-01-17 10:50:33 +01:00
|
|
|
setDefaultSort,
|
2018-01-18 10:53:54 +01:00
|
|
|
setDefaultPagination,
|
2017-11-30 10:51:13 +01:00
|
|
|
asyncMiddleware(listJobs)
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
jobsRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) {
|
2017-12-12 17:53:50 +01:00
|
|
|
const resultList = await JobModel.listForApi(req.query.start, req.query.count, req.query.sort)
|
2017-11-30 10:51:13 +01:00
|
|
|
|
|
|
|
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
|
|
|
}
|