Created
February 2, 2017 18:19
-
-
Save crizstian/90401a1cb37cbeb22719be8ee5ea28f3 to your computer and use it in GitHub Desktop.
Example of schema validation with joi
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
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 |
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
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 |
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
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