Removing ng-di on the server.
This commit is contained in:
parent
ddb2f47a9d
commit
8697d79ba5
37 changed files with 2838 additions and 2878 deletions
|
|
@ -1,83 +1,82 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng').factory('MonitoringResource', function (
|
||||
Constraints,
|
||||
Validator,
|
||||
MonitoringService,
|
||||
Logger,
|
||||
_,
|
||||
Strings,
|
||||
Resources,
|
||||
ErrorTypes
|
||||
) {
|
||||
var isValidToken = Validator.forConstraint(Constraints.token);
|
||||
const _ = require('lodash')
|
||||
|
||||
return {
|
||||
getAll: function (req, res) {
|
||||
Resources.getValidRestParams('list', null, req, function (err, restParams) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
const Constraints = require('../../shared/validation/constraints')
|
||||
const ErrorTypes = require('../utils/errorTypes')
|
||||
const Logger = require('../logger')
|
||||
const MonitoringService = require('../services/monitoringService')
|
||||
const Resources = require('../utils/resources')
|
||||
const Strings = require('../utils/strings')
|
||||
const Validator = require('../validation/validator')
|
||||
|
||||
return MonitoringService.getAll(
|
||||
restParams,
|
||||
function (err, monitoringStates, total) {
|
||||
if (err) {
|
||||
Logger.tag('monitoring', 'admin').error('Could not get monitoring states:', err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
const isValidToken = Validator.forConstraint(Constraints.token);
|
||||
|
||||
res.set('X-Total-Count', total);
|
||||
return Resources.success(res, _.map(monitoringStates, function (state) {
|
||||
state.mapId = _.toLower(state.mac).replace(/:/g, '');
|
||||
return state;
|
||||
}));
|
||||
module.exports = {
|
||||
getAll (req, res) {
|
||||
Resources.getValidRestParams('list', null, req, function (err, restParams) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
|
||||
return MonitoringService.getAll(
|
||||
restParams,
|
||||
function (err, monitoringStates, total) {
|
||||
if (err) {
|
||||
Logger.tag('monitoring', 'admin').error('Could not get monitoring states:', err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
confirm: function (req, res) {
|
||||
var data = Resources.getData(req);
|
||||
|
||||
var token = Strings.normalizeString(data.token);
|
||||
if (!isValidToken(token)) {
|
||||
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
|
||||
}
|
||||
|
||||
return MonitoringService.confirm(token, function (err, node) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
res.set('X-Total-Count', total);
|
||||
return Resources.success(res, _.map(monitoringStates, function (state) {
|
||||
state.mapId = _.toLower(state.mac).replace(/:/g, '');
|
||||
return state;
|
||||
}));
|
||||
}
|
||||
return Resources.success(res, {
|
||||
hostname: node.hostname,
|
||||
mac: node.mac,
|
||||
email: node.email,
|
||||
monitoring: node.monitoring,
|
||||
monitoringConfirmed: node.monitoringConfirmed
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
disable: function (req, res) {
|
||||
var data = Resources.getData(req);
|
||||
confirm (req, res) {
|
||||
const data = Resources.getData(req);
|
||||
|
||||
var token = Strings.normalizeString(data.token);
|
||||
if (!isValidToken(token)) {
|
||||
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
|
||||
}
|
||||
|
||||
return MonitoringService.disable(token, function (err, node) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
return Resources.success(res, {
|
||||
hostname: node.hostname,
|
||||
mac: node.mac,
|
||||
email: node.email,
|
||||
monitoring: node.monitoring
|
||||
});
|
||||
});
|
||||
const token = Strings.normalizeString(data.token);
|
||||
if (!isValidToken(token)) {
|
||||
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return MonitoringService.confirm(token, function (err, node) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
return Resources.success(res, {
|
||||
hostname: node.hostname,
|
||||
mac: node.mac,
|
||||
email: node.email,
|
||||
monitoring: node.monitoring,
|
||||
monitoringConfirmed: node.monitoringConfirmed
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
disable (req, res) {
|
||||
const data = Resources.getData(req);
|
||||
|
||||
const token = Strings.normalizeString(data.token);
|
||||
if (!isValidToken(token)) {
|
||||
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
|
||||
}
|
||||
|
||||
return MonitoringService.disable(token, function (err, node) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
return Resources.success(res, {
|
||||
hostname: node.hostname,
|
||||
mac: node.mac,
|
||||
email: node.email,
|
||||
monitoring: node.monitoring
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue