From f831dd79265794f6b313639adc0b5ef49b27537a Mon Sep 17 00:00:00 2001 From: Olivier Berthonneau Date: Mon, 11 Jul 2016 12:11:39 +0200 Subject: [PATCH] JsonApiService.validate can validate document given a context --- lib/api/services/JsonApiService.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/api/services/JsonApiService.js b/lib/api/services/JsonApiService.js index 8f00beb..36b695a 100644 --- a/lib/api/services/JsonApiService.js +++ b/lib/api/services/JsonApiService.js @@ -1,8 +1,8 @@ const _ = require("lodash"); const cleanObject = require('clean-object'); const JSONAPISerializer = require('json-api-serializer'); +const jsonApiValidator = require('../../context-aware-jsonapi-validator/validator'); const Serializer = new JSONAPISerializer(); -const JSONAPIValidator = require('jsonapi-validator').Validator; var findRecords = require('../blueprints/find'); var findOneRecord = require('../blueprints/findone'); @@ -156,16 +156,8 @@ module.exports = { return errors; }, - validate: function(data) { + validate: function(doc, strategy) { - var validator = new JSONAPIValidator(); - - try { - validator.validate(data); - - return true; - } catch (e) { - return false; - } + return jsonApiValidator.isValid(doc, strategy); } }