Best JavaScript code snippets using joi.date
cli/templates/models/schemas/foo.js/Joi.object.keys
Joi.object().keys({
id : Joi.number().integer(),
firstname : Joi.string().max(128).optional(),
lastname : Joi.string().max(128).optional(),
created_at : Joi.date().default(() => moment().format(), 'date created'),
updated_at : Joi.date().default(() => moment().format(), 'date updated'),
})
app/employee-model.js/Employee/schema
// schema validation using joi
static schema () {
return {
employeeNumber: joi.number().integer(),
firstname: joi.string().alphanum().min(3).max(30).required(),
lastname: joi.string().alphanum().min(3).max(30).required(),
grade: joi.string().regex(/^[a-zA-Z0-9]{3}$/).required(),
birthDate: joi.date().raw().required(),
joinDate: joi.date().raw().required(),
salary: joi.number().required(),
email: joi.string().email()
}
}
origin: jkbhatnagar/dev-samples-aws-serverless-nodejs-mongodb-restapi
api/products.js/validateProduct
function validateProduct(data, callback){
const schema = Joi.object().keys({
id: Joi.string().guid().required(),
title: Joi.string().min(3).max(50).required(),
description: Joi.string().min(3).max(50),
unit: Joi.string().min(1).max(10).required(),
price: Joi.number().positive().greater(0).required(),
updatedat: Joi.date().timestamp(),
});
Joi.validate(data, schema, (err, value) => {
if (err) {
callback(err);
}
else{
callback(null);
}
});
}
app.js/app.post
birthday: Joi.date().max('1-1-2004').iso(),
'Node.js > Jest' 카테고리의 다른 글
[Jest] set, clear and reset mock/spy/stub implementation (0) | 2022.04.16 |
---|---|
[Jest] Jest Mock Functions (0) | 2022.04.15 |
[Node.js] Jest worker encountered 4 child process exceptions, exceeding retry limit (0) | 2022.04.07 |
[JEST] describe (0) | 2022.04.02 |
[JEST] Jest Functions with AWS (0) | 2022.04.02 |