aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/requests.js
blob: 1f9193fc87fd56ea2b23ac7010d77539ce436bd8 (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
'use strict'

const express = require('express')

const constants = require('../../initializers/constants')
const db = require('../../initializers/database')
const middlewares = require('../../middlewares')
const admin = middlewares.admin
const oAuth = middlewares.oauth

const router = express.Router()

router.get('/stats',
  oAuth.authenticate,
  admin.ensureIsAdmin,
  getStatsRequests
)

// ---------------------------------------------------------------------------

module.exports = router

// ---------------------------------------------------------------------------

function getStatsRequests (req, res, next) {
  db.Request.countTotalRequests(function (err, totalRequests) {
    if (err) return next(err)

    return res.json({
      totalRequests: totalRequests,
      maxRequestsInParallel: constants.REQUESTS_IN_PARALLEL,
      remainingMilliSeconds: db.Request.remainingMilliSeconds(),
      milliSecondsInterval: constants.REQUESTS_INTERVAL
    })
  })
}