aboutsummaryrefslogtreecommitdiffhomepage
path: root/controllers/api/v1/pods.js
diff options
context:
space:
mode:
Diffstat (limited to 'controllers/api/v1/pods.js')
-rw-r--r--controllers/api/v1/pods.js46
1 files changed, 26 insertions, 20 deletions
diff --git a/controllers/api/v1/pods.js b/controllers/api/v1/pods.js
index 30385bd5a..b073e85af 100644
--- a/controllers/api/v1/pods.js
+++ b/controllers/api/v1/pods.js
@@ -2,20 +2,27 @@
2 'use strict' 2 'use strict'
3 3
4 var express = require('express') 4 var express = require('express')
5 var router = express.Router() 5
6 var middleware = require('../../../middlewares') 6 var middleware = require('../../../middlewares')
7 var miscMiddleware = middleware.misc 7 var miscMiddleware = middleware.misc
8 var pods = require('../../../models/pods')
8 var reqValidator = middleware.reqValidators.pods 9 var reqValidator = middleware.reqValidators.pods
9 var secureRequest = middleware.reqValidators.remote.secureRequest 10 var secureRequest = middleware.reqValidators.remote.secureRequest
10 var pods = require('../../../models/pods')
11 11
12 function listPods (req, res, next) { 12 var router = express.Router()
13 pods.list(function (err, pods_list) {
14 if (err) return next(err)
15 13
16 res.json(pods_list) 14 router.get('/', miscMiddleware.cache(false), listPods)
17 }) 15 router.post('/', reqValidator.podsAdd, miscMiddleware.cache(false), addPods)
18 } 16 router.get('/makefriends', miscMiddleware.cache(false), makeFriends)
17 router.get('/quitfriends', miscMiddleware.cache(false), quitFriends)
18 // Post because this is a secured request
19 router.post('/remove', secureRequest, miscMiddleware.decryptBody, removePods)
20
21 // ---------------------------------------------------------------------------
22
23 module.exports = router
24
25 // ---------------------------------------------------------------------------
19 26
20 function addPods (req, res, next) { 27 function addPods (req, res, next) {
21 pods.add(req.body.data, function (err, json) { 28 pods.add(req.body.data, function (err, json) {
@@ -25,11 +32,11 @@
25 }) 32 })
26 } 33 }
27 34
28 function removePods (req, res, next) { 35 function listPods (req, res, next) {
29 pods.remove(req.body.signature.url, function (err) { 36 pods.list(function (err, pods_list) {
30 if (err) return next(err) 37 if (err) return next(err)
31 38
32 res.sendStatus(204) 39 res.json(pods_list)
33 }) 40 })
34 } 41 }
35 42
@@ -50,20 +57,19 @@
50 }) 57 })
51 } 58 }
52 59
53 function quitFriends (req, res, next) { 60 function removePods (req, res, next) {
54 pods.quitFriends(function (err) { 61 pods.remove(req.body.signature.url, function (err) {
55 if (err) return next(err) 62 if (err) return next(err)
56 63
57 res.sendStatus(204) 64 res.sendStatus(204)
58 }) 65 })
59 } 66 }
60 67
61 router.get('/', miscMiddleware.cache(false), listPods) 68 function quitFriends (req, res, next) {
62 router.get('/makefriends', miscMiddleware.cache(false), makeFriends) 69 pods.quitFriends(function (err) {
63 router.get('/quitfriends', miscMiddleware.cache(false), quitFriends) 70 if (err) return next(err)
64 router.post('/', reqValidator.podsAdd, miscMiddleware.cache(false), addPods)
65 // Post because this is a secured request
66 router.post('/remove', secureRequest, miscMiddleware.decryptBody, removePods)
67 71
68 module.exports = router 72 res.sendStatus(204)
73 })
74 }
69})() 75})()