blob: 17aca8af0e0b641446e7846b5b1f31f67ace021a (
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
|
'use strict'
const express = require('express')
const mongoose = require('mongoose')
const constants = require('../../../initializers/constants')
const middlewares = require('../../../middlewares')
const admin = middlewares.admin
const oAuth = middlewares.oauth
const Request = mongoose.model('Request')
const router = express.Router()
router.get('/stats',
oAuth.authenticate,
admin.ensureIsAdmin,
getStatsRequests
)
// ---------------------------------------------------------------------------
module.exports = router
// ---------------------------------------------------------------------------
function getStatsRequests (req, res, next) {
Request.list(function (err, requests) {
if (err) return next(err)
const remainingMilliSeconds = constants.REQUESTS_INTERVAL - (Date.now() % constants.REQUESTS_INTERVAL)
return res.json({
requests: requests,
remainingMilliSeconds: remainingMilliSeconds,
milliSecondsInterval: constants.REQUESTS_INTERVAL
})
})
}
|