2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2022-09-15 11:28:41 +02:00
|
|
|
getSystemGraphs,
|
2022-09-14 13:03:14 +02:00
|
|
|
getAppGraphs
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2022-09-14 13:03:14 +02:00
|
|
|
const assert = require('assert'),
|
|
|
|
|
graphs = require('../graphs.js'),
|
2019-09-05 12:01:25 -07:00
|
|
|
HttpError = require('connect-lastmile').HttpError,
|
2022-08-08 13:06:14 +02:00
|
|
|
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
2022-09-15 11:28:41 +02:00
|
|
|
safe = require('safetydance');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2022-09-15 11:28:41 +02:00
|
|
|
async function getSystemGraphs(req, res, next) {
|
|
|
|
|
if (!req.query.fromMinutes || !parseInt(req.query.fromMinutes)) return next(new HttpError(400, 'fromMinutes must be a number'));
|
2019-09-05 12:01:25 -07:00
|
|
|
|
2022-09-15 11:28:41 +02:00
|
|
|
const fromMinutes = parseInt(req.query.fromMinutes);
|
|
|
|
|
const noNullPoints = !!req.query.noNullPoints;
|
|
|
|
|
const [error, result] = await safe(graphs.getSystem(fromMinutes, noNullPoints));
|
|
|
|
|
if (error) return next(new HttpError(500, error));
|
2019-09-05 12:01:25 -07:00
|
|
|
|
2022-09-15 11:28:41 +02:00
|
|
|
next(new HttpSuccess(200, result));
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 13:03:14 +02:00
|
|
|
async function getAppGraphs(req, res, next) {
|
|
|
|
|
assert.strictEqual(typeof req.app, 'object');
|
|
|
|
|
|
|
|
|
|
if (!req.query.fromMinutes || !parseInt(req.query.fromMinutes)) return next(new HttpError(400, 'fromMinutes must be a number'));
|
|
|
|
|
|
2022-08-08 13:06:14 +02:00
|
|
|
const fromMinutes = parseInt(req.query.fromMinutes);
|
2022-09-14 13:03:14 +02:00
|
|
|
const noNullPoints = !!req.query.noNullPoints;
|
2022-09-16 09:40:47 +02:00
|
|
|
const [error, result] = await safe(graphs.getByApp(req.app, fromMinutes, noNullPoints));
|
2022-09-14 13:03:14 +02:00
|
|
|
if (error) return next(new HttpError(500, error));
|
|
|
|
|
|
|
|
|
|
next(new HttpSuccess(200, result));
|
|
|
|
|
}
|