Skip to content

Instantly share code, notes, and snippets.

@crizstian
Created February 2, 2017 18:19
Show Gist options
  • Save crizstian/90401a1cb37cbeb22719be8ee5ea28f3 to your computer and use it in GitHub Desktop.
Save crizstian/90401a1cb37cbeb22719be8ee5ea28f3 to your computer and use it in GitHub Desktop.
Example of schema validation with joi
const bookingSchema = (joi) => ({
bookingSchema: joi.object().keys({
city: joi.string(),
schedule: joi.date().min('now'),
movie: joi.string(),
cinemaRoom: joi.number(),
seats: joi.array().items(joi.string()).single(),
totalAmount: joi.number()
})
})
module.exports = bookingSchema
const ticketSchema = (joi) => ({
ticketSchema: joi.object().keys({
cinema: joi.string(),
schedule: joi.date().min('now'),
movie: joi.string(),
seat: joi.array().items(joi.string()).single(),
cinemaRoom: joi.number(),
orderId: joi.number()
})
})
module.exports = ticketSchema
const userSchema = (joi) => ({
userSchema: joi.object().keys({
name: joi.string().regex(/^[a-bA-B]+/).required(),
lastName: joi.string().regex(/^[a-bA-B]+/).required(),
email: joi.string().email().required(),
phoneNumber: joi.string().regex(/^(\+0?1\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$/),
creditCard: joi.string().creditCard().required(),
membership: joi.number().creditCard()
})
})
module.exports = userSchema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment