2017-06-05 14:53:49 -05:00
|
|
|
import * as express from 'express'
|
2017-11-10 10:27:49 -06:00
|
|
|
import { getFormattedObjects } from '../../helpers'
|
2017-05-22 13:58:25 -05:00
|
|
|
import { database as db } from '../../initializers/database'
|
2017-11-10 10:27:49 -06:00
|
|
|
import { asyncMiddleware, paginationValidator, podsSortValidator, setPagination, setPodsSort } from '../../middlewares'
|
2017-05-15 15:22:03 -05:00
|
|
|
|
|
|
|
const podsRouter = express.Router()
|
|
|
|
|
2017-10-19 02:43:01 -05:00
|
|
|
podsRouter.get('/',
|
|
|
|
paginationValidator,
|
|
|
|
podsSortValidator,
|
|
|
|
setPodsSort,
|
|
|
|
setPagination,
|
2017-10-25 04:55:06 -05:00
|
|
|
asyncMiddleware(listPods)
|
2017-05-15 15:22:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
podsRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-10-25 04:55:06 -05:00
|
|
|
async function listPods (req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
|
|
const resultList = await db.Pod.listForApi(req.query.start, req.query.count, req.query.sort)
|
|
|
|
|
|
|
|
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
2017-05-15 15:22:03 -05:00
|
|
|
}
|