aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/pods.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/pods.ts')
-rw-r--r--server/controllers/api/pods.ts33
1 files changed, 26 insertions, 7 deletions
diff --git a/server/controllers/api/pods.ts b/server/controllers/api/pods.ts
index 43df3f66f..aa07b17f6 100644
--- a/server/controllers/api/pods.ts
+++ b/server/controllers/api/pods.ts
@@ -1,16 +1,27 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getFormattedObjects } from '../../helpers' 2import { getFormattedObjects } from '../../helpers'
3import { getApplicationAccount } from '../../helpers/utils'
3import { database as db } from '../../initializers/database' 4import { database as db } from '../../initializers/database'
4import { asyncMiddleware, paginationValidator, podsSortValidator, setPagination, setPodsSort } from '../../middlewares' 5import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../middlewares'
6import { setFollowingSort } from '../../middlewares/sort'
7import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort'
5 8
6const podsRouter = express.Router() 9const podsRouter = express.Router()
7 10
8podsRouter.get('/', 11podsRouter.get('/following',
9 paginationValidator, 12 paginationValidator,
10 podsSortValidator, 13 followingSortValidator,
11 setPodsSort, 14 setFollowingSort,
12 setPagination, 15 setPagination,
13 asyncMiddleware(listPods) 16 asyncMiddleware(listFollowing)
17)
18
19podsRouter.get('/followers',
20 paginationValidator,
21 followersSortValidator,
22 setFollowersSort,
23 setPagination,
24 asyncMiddleware(listFollowers)
14) 25)
15 26
16// --------------------------------------------------------------------------- 27// ---------------------------------------------------------------------------
@@ -21,8 +32,16 @@ export {
21 32
22// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
23 34
24async function listPods (req: express.Request, res: express.Response, next: express.NextFunction) { 35async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) {
25 const resultList = await db.Pod.listForApi(req.query.start, req.query.count, req.query.sort) 36 const applicationAccount = await getApplicationAccount()
37 const resultList = await db.Account.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
38
39 return res.json(getFormattedObjects(resultList.data, resultList.total))
40}
41
42async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) {
43 const applicationAccount = await getApplicationAccount()
44 const resultList = await db.Account.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
26 45
27 return res.json(getFormattedObjects(resultList.data, resultList.total)) 46 return res.json(getFormattedObjects(resultList.data, resultList.total))
28} 47}