aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/api/v1/pods.js
blob: 2bb8f89abfdbd407d8c2ec99d13c87bd25fc3110 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
;(function () {
  'use strict'

  var express = require('express')
  var router = express.Router()
  var middleware = require('../../../middlewares')
  var miscMiddleware = middleware.misc
  var reqValidator = middleware.reqValidators.pods
  var pods = require('../../../src/pods')

  function listPods (req, res, next) {
    pods.list(function (err, pods_list) {
      if (err) return next(err)

      res.json(pods_list)
    })
  }

  function addPods (req, res, next) {
    pods.add(req.body.data, function (err, json) {
      if (err) return next(err)

      res.json(json)
    })
  }

  function makeFriends (req, res, next) {
    pods.makeFriends(function (err) {
      if (err) return next(err)

      res.sendStatus(204)
    })
  }

  router.get('/', miscMiddleware.cache(false), listPods)
  router.get('/makefriends', miscMiddleware.cache(false), makeFriends)
  router.post('/', reqValidator.podsAdd, miscMiddleware.cache(false), addPods)

  module.exports = router
})()