Created
June 11, 2018 21:53
-
-
Save kPOWz/c3af2b15a5ef6112eccbb84f798d68d3 to your computer and use it in GitHub Desktop.
Revisions
-
kPOWz created this gist
Jun 11, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ rules: [ { name: 'xorWithAllPaths', params: {peers: Joi.array()}, validate(params, value, state, options) { if (value !== null && params) { const xOrError = Joi.object() .keys({discountAmount: Joi.number(), discountPercentage: Joi.number()}) .xor('discountAmount', 'discountPercentage') .options({allowUnknown: true}) .validate(value).error; console.log(`errorz: ${xOrError}`); // const discountAmountState = Object.assign({}, state, {path: ['discountAmount']}); // const discountPercentageState = Object.assign({}, state, {path: ['discountPercentage']}); if (xOrError) { return this.createError('object.xor', {peers: params.peers}, state, options); // return this.createError('object.xor', {peers: params.peers}, state, options); // [xOrError, // this.createError('object.xor', {value}, discountAmountState, options), // this.createError('object.xor', {value}, discountPercentageState, options)]; } return value; } return value; } } ]