Skip to content

Instantly share code, notes, and snippets.

@kPOWz
Created June 11, 2018 21:53
Show Gist options
  • Select an option

  • Save kPOWz/c3af2b15a5ef6112eccbb84f798d68d3 to your computer and use it in GitHub Desktop.

Select an option

Save kPOWz/c3af2b15a5ef6112eccbb84f798d68d3 to your computer and use it in GitHub Desktop.
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