1
0
Fork 0
peertube/server/controllers/api/pods.ts
2017-11-27 19:40:51 +01:00

28 lines
890 B
TypeScript

import * as express from 'express'
import { getFormattedObjects } from '../../helpers'
import { database as db } from '../../initializers/database'
import { asyncMiddleware, paginationValidator, podsSortValidator, setPagination, setPodsSort } from '../../middlewares'
const podsRouter = express.Router()
podsRouter.get('/',
paginationValidator,
podsSortValidator,
setPodsSort,
setPagination,
asyncMiddleware(listPods)
)
// ---------------------------------------------------------------------------
export {
podsRouter
}
// ---------------------------------------------------------------------------
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))
}