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.

Revisions

  1. kPOWz created this gist Jun 11, 2018.
    28 changes: 28 additions & 0 deletions xorExtension
    Original 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;
    }
    }
    ]