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.ts53
1 files changed, 15 insertions, 38 deletions
diff --git a/server/controllers/api/pods.ts b/server/controllers/api/pods.ts
index e1e8ff6ca..ec94efc35 100644
--- a/server/controllers/api/pods.ts
+++ b/server/controllers/api/pods.ts
@@ -1,39 +1,33 @@
1import * as express from 'express' 1import * as express from 'express'
2 2
3import { database as db } from '../../initializers/database' 3import { database as db } from '../../initializers/database'
4import { CONFIG } from '../../initializers' 4import { logger, getFormattedObjects } from '../../helpers'
5import { 5import {
6 logger,
7 getMyPublicCert,
8 getFormattedObjects
9} from '../../helpers'
10import {
11 sendOwnedVideosToPod,
12 makeFriends, 6 makeFriends,
13 quitFriends, 7 quitFriends,
14 removeFriend 8 removeFriend
15} from '../../lib' 9} from '../../lib'
16import { 10import {
17 podsAddValidator,
18 authenticate, 11 authenticate,
19 ensureIsAdmin, 12 ensureIsAdmin,
20 makeFriendsValidator, 13 makeFriendsValidator,
21 setBodyHostPort,
22 setBodyHostsPort, 14 setBodyHostsPort,
23 podRemoveValidator 15 podRemoveValidator,
16 paginationValidator,
17 setPagination,
18 setPodsSort,
19 podsSortValidator
24} from '../../middlewares' 20} from '../../middlewares'
25import { 21import { PodInstance } from '../../models'
26 PodInstance
27} from '../../models'
28import { Pod as FormattedPod } from '../../../shared'
29 22
30const podsRouter = express.Router() 23const podsRouter = express.Router()
31 24
32podsRouter.get('/', listPods) 25podsRouter.get('/',
33podsRouter.post('/', 26 paginationValidator,
34 setBodyHostPort, // We need to modify the host before running the validator! 27 podsSortValidator,
35 podsAddValidator, 28 setPodsSort,
36 addPods 29 setPagination,
30 listPods
37) 31)
38podsRouter.post('/make-friends', 32podsRouter.post('/make-friends',
39 authenticate, 33 authenticate,
@@ -62,26 +56,9 @@ export {
62 56
63// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
64 58
65function addPods (req: express.Request, res: express.Response, next: express.NextFunction) {
66 const informations = req.body
67
68 const pod = db.Pod.build(informations)
69 pod.save()
70 .then(podCreated => {
71 return sendOwnedVideosToPod(podCreated.id)
72 })
73 .then(() => {
74 return getMyPublicCert()
75 })
76 .then(cert => {
77 return res.json({ cert: cert, email: CONFIG.ADMIN.EMAIL })
78 })
79 .catch(err => next(err))
80}
81
82function listPods (req: express.Request, res: express.Response, next: express.NextFunction) { 59function listPods (req: express.Request, res: express.Response, next: express.NextFunction) {
83 db.Pod.list() 60 db.Pod.listForApi(req.query.start, req.query.count, req.query.sort)
84 .then(podsList => res.json(getFormattedObjects<FormattedPod, PodInstance>(podsList, podsList.length))) 61 .then(resultList => res.json(getFormattedObjects(resultList.data, resultList.total)))
85 .catch(err => next(err)) 62 .catch(err => next(err))
86} 63}
87 64