1 import * as express from 'express'
2 import { getFormattedObjects } from '../../helpers'
3 import { getApplicationAccount } from '../../helpers/utils'
4 import { database as db } from '../../initializers/database'
5 import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../middlewares'
6 import { setFollowingSort } from '../../middlewares/sort'
7 import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort'
9 const podsRouter = express.Router()
11 podsRouter.get('/following',
13 followingSortValidator,
16 asyncMiddleware(listFollowing)
19 podsRouter.get('/followers',
21 followersSortValidator,
24 asyncMiddleware(listFollowers)
27 // ---------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------
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)
39 return res.json(getFormattedObjects(resultList.data, resultList.total))
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)
46 return res.json(getFormattedObjects(resultList.data, resultList.total))