]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/pods.ts
Handle follow/accept
[github/Chocobozzz/PeerTube.git] / server / controllers / api / pods.ts
CommitLineData
4d4e5cd4 1import * as express from 'express'
571389d4 2import { getFormattedObjects } from '../../helpers'
7a7724e6 3import { getApplicationAccount } from '../../helpers/utils'
e02643f3 4import { database as db } from '../../initializers/database'
7a7724e6
C
5import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../middlewares'
6import { setFollowingSort } from '../../middlewares/sort'
7import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort'
65fcc311
C
8
9const podsRouter = express.Router()
10
7a7724e6 11podsRouter.get('/following',
8a02bd04 12 paginationValidator,
7a7724e6
C
13 followingSortValidator,
14 setFollowingSort,
8a02bd04 15 setPagination,
7a7724e6
C
16 asyncMiddleware(listFollowing)
17)
18
19podsRouter.get('/followers',
20 paginationValidator,
21 followersSortValidator,
22 setFollowersSort,
23 setPagination,
24 asyncMiddleware(listFollowers)
65fcc311 25)
65fcc311
C
26
27// ---------------------------------------------------------------------------
28
29export {
30 podsRouter
31}
32
33// ---------------------------------------------------------------------------
34
7a7724e6
C
35async 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
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)
eb080476
C
45
46 return res.json(getFormattedObjects(resultList.data, resultList.total))
65fcc311 47}