37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
exports = module.exports = {
|
|
getSystemGraphs,
|
|
getAppGraphs
|
|
};
|
|
|
|
const assert = require('assert'),
|
|
graphs = require('../graphs.js'),
|
|
HttpError = require('connect-lastmile').HttpError,
|
|
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
|
safe = require('safetydance');
|
|
|
|
async function getSystemGraphs(req, res, next) {
|
|
if (!req.query.fromMinutes || !parseInt(req.query.fromMinutes)) return next(new HttpError(400, 'fromMinutes must be a number'));
|
|
|
|
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));
|
|
|
|
next(new HttpSuccess(200, result));
|
|
}
|
|
|
|
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'));
|
|
|
|
const fromMinutes = parseInt(req.query.fromMinutes);
|
|
const noNullPoints = !!req.query.noNullPoints;
|
|
const [error, result] = await safe(graphs.getByApp(req.app, fromMinutes, noNullPoints));
|
|
if (error) return next(new HttpError(500, error));
|
|
|
|
next(new HttpSuccess(200, result));
|
|
}
|