aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/pods.ts
blob: 43df3f66f3b79e21d225e3f306f1239f85de8423 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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))
}