Skip to content

Commit

Permalink
All input json api data are validated before proceeding
Browse files Browse the repository at this point in the history
  • Loading branch information
dynamiccast committed Jul 11, 2016
1 parent f831dd7 commit 2a06020
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var BlueprintController = {
, populate: require('./api/blueprints/populate')
};
var JsonApiService = require('./api/services/JsonApiService');
var jsonApiValidator = require('./context-aware-jsonapi-validator/validator');
var responseOk = require('./api/responses/ok');
var responseCreated = require('./api/responses/created');
var responseNotFound = require('./api/responses/notFound');
Expand Down Expand Up @@ -137,9 +138,12 @@ module.exports = function(sails) {
if (strncmp(controller[name]._middlewareType, "BLUEPRINT: ", "BLUEPRINT: ".length) === true) {
controller[name] = function(req, res) {

if (req.method !== 'GET' && req.method !== 'DELETE' &&
JsonApiService.validate(req.body) === false) {
return res.invalidJsonApi();
if (req.method === 'POST' || req.method === 'PATCH') {

var context = (req.method === 'POST') ? jsonApiValidator.CONTEXT_CREATE : jsonApiValidator.CONTEXT_UPDATE;

if (JsonApiService.validate(req.body, context) === false)
return res.invalidJsonApi();
}

req.body = JsonApiService.deserialize(req.body);
Expand Down

0 comments on commit 2a06020

Please sign in to comment.