ffffng/server/resources/monitoringResource.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
angular.module('ffffng').factory('MonitoringResource', function (
Constraints,
Validator,
MonitoringService,
_,
Strings,
Resources,
ErrorTypes
) {
var isValidToken = Validator.forConstraint(Constraints.token);
return {
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});
}
2016-05-23 22:36:27 +02:00
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,
2016-05-18 23:15:43 +02:00
monitoring: node.monitoring,
monitoringConfirmed: node.monitoringConfirmed
});
});
2016-05-18 23:15:43 +02:00
},
disable: 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});
}
2016-05-23 22:36:27 +02:00
return MonitoringService.disable(token, function (err, node) {
2016-05-18 23:15:43 +02:00
if (err) {
return Resources.error(res, err);
}
return Resources.success(res, {
hostname: node.hostname,
mac: node.mac,
email: node.email,
monitoring: node.monitoring
});
});
}
};
});