Created
June 11, 2018 21:53
-
-
Save kPOWz/c3af2b15a5ef6112eccbb84f798d68d3 to your computer and use it in GitHub Desktop.
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 characters
| 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; | |
| } | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment