express-api-cli
Version:
Cli tool for generating an express project. Instead of wasting extra time creating your project structure, start building right away
18 lines (15 loc) • 415 B
text/typescript
import Joi from '@hapi/joi';
import { Request, Response, NextFunction } from 'express';
class UserValidator {
public newUser = (req: Request, res: Response, next: NextFunction): void => {
const schema = Joi.object({
name: Joi.string().min(4).required()
});
const { error } = schema.validate(req.body);
if (error) {
next(error);
}
next();
};
}
export default UserValidator;