]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as express from 'express' |
571389d4 | 2 | import { getFormattedObjects } from '../../helpers' |
7a7724e6 | 3 | import { getApplicationAccount } from '../../helpers/utils' |
e02643f3 | 4 | import { database as db } from '../../initializers/database' |
7a7724e6 C |
5 | import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../middlewares' |
6 | import { setFollowingSort } from '../../middlewares/sort' | |
7 | import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort' | |
65fcc311 C |
8 | |
9 | const podsRouter = express.Router() | |
10 | ||
7a7724e6 | 11 | podsRouter.get('/following', |
8a02bd04 | 12 | paginationValidator, |
7a7724e6 C |
13 | followingSortValidator, |
14 | setFollowingSort, | |
8a02bd04 | 15 | setPagination, |
7a7724e6 C |
16 | asyncMiddleware(listFollowing) |
17 | ) | |
18 | ||
19 | podsRouter.get('/followers', | |
20 | paginationValidator, | |
21 | followersSortValidator, | |
22 | setFollowersSort, | |
23 | setPagination, | |
24 | asyncMiddleware(listFollowers) | |
65fcc311 | 25 | ) |
65fcc311 C |
26 | |
27 | // --------------------------------------------------------------------------- | |
28 | ||
29 | export { | |
30 | podsRouter | |
31 | } | |
32 | ||
33 | // --------------------------------------------------------------------------- | |
34 | ||
7a7724e6 C |
35 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { |
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 | ||
42 | async 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) | |
eb080476 C |
45 | |
46 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | |
65fcc311 | 47 | } |