Skip to content

Instantly share code, notes, and snippets.

@samueljoli
Created January 30, 2017 18:05
Show Gist options
  • Select an option

  • Save samueljoli/dba973b2d8a2341113d40a07f749999d to your computer and use it in GitHub Desktop.

Select an option

Save samueljoli/dba973b2d8a2341113d40a07f749999d to your computer and use it in GitHub Desktop.
// assuming we are already defining Hapi server routes
const payloadSchema = Joi.object().keys({
id : Joi.string().guid().required(),
name : Joi.string().min(3).required(),
callRequested: Joi.boolean().optional(),
phoneNumber : Joi.when(‘callRequested’, {
is : true,
then : Joi.string().min(10).required(),
otherwise: Joi.string().allow(null).optional()
})
});
server.route({
method : 'POST',
path : '/document',
handler: plugin.post,
config : {
validate: payloadSchema
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment