]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/pods.ts
Handle follow/accept
[github/Chocobozzz/PeerTube.git] / server / controllers / api / pods.ts
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'
8
9 const podsRouter = express.Router()
10
11 podsRouter.get('/following',
12 paginationValidator,
13 followingSortValidator,
14 setFollowingSort,
15 setPagination,
16 asyncMiddleware(listFollowing)
17 )
18
19 podsRouter.get('/followers',
20 paginationValidator,
21 followersSortValidator,
22 setFollowersSort,
23 setPagination,
24 asyncMiddleware(listFollowers)
25 )
26
27 // ---------------------------------------------------------------------------
28
29 export {
30 podsRouter
31 }
32
33 // ---------------------------------------------------------------------------
34
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)
45
46 return res.json(getFormattedObjects(resultList.data, resultList.total))
47 }