Extended node management in amdin panel.
This commit is contained in:
parent
d5c69fa78f
commit
0f1a21c905
10 changed files with 152 additions and 32 deletions
server/utils
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng').factory('Resources', function (_) {
|
||||
angular.module('ffffng').factory('Resources', function (_, Constraints, Validator, ErrorTypes) {
|
||||
function respond(res, httpCode, data) {
|
||||
res.writeHead(httpCode, {'Content-Type': 'application/json'});
|
||||
res.end(JSON.stringify(data));
|
||||
|
@ -11,6 +11,31 @@ angular.module('ffffng').factory('Resources', function (_) {
|
|||
return _.extend({}, req.body, req.params, req.query);
|
||||
},
|
||||
|
||||
getValidRestParams: function(type, req, callback) {
|
||||
var constraints = Constraints.rest[type];
|
||||
if (!_.isPlainObject(constraints)) {
|
||||
Logger.tag('validation', 'rest').error('Unknown REST resource type: {}', type);
|
||||
return callback({data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
|
||||
var data = this.getData(req);
|
||||
|
||||
var restParams = {};
|
||||
_.each(_.keys(constraints), function (key) {
|
||||
var value = data[key];
|
||||
restParams[key] = _.isUndefined(value) && !_.isUndefined(constraints[key].default)
|
||||
? constraints[key].default
|
||||
: value;
|
||||
});
|
||||
|
||||
var areValidParams = Validator.forConstraints(constraints);
|
||||
if (!areValidParams(restParams)) {
|
||||
return callback({data: 'Invalid REST parameters.', type: ErrorTypes.badRequest});
|
||||
}
|
||||
|
||||
callback(null, restParams);
|
||||
},
|
||||
|
||||
success: function (res, data) {
|
||||
respond(res, 200, data);
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue