123456789101112131415161718192021222324252627282930313233343536373839 |
- const Joi = require('joi');
- const validate = require('./validate');
- const schemaCreateNewUser = Joi.object({
- number: Joi.string().min(8).max(14).required(),
- country: Joi.string().min(1).max(40).required(),
- }).min(2);
- const schemaUpdateUser = Joi.object({
- name: Joi.string().min(3).max(30).optional().trim().optional(),
- lastName: Joi.string().min(3).max(30).optional().trim().optional(),
- }).min(1);
- const schemaLogIn = Joi.object({
- number: Joi.string().min(8).max(14).required(),
- code: Joi.string().min(3).max(12).required(),
- }).min(2);
- module.exports.registration = (req, _res, next) => {
- return validate(schemaCreateNewUser, req.body, next);
- };
- module.exports.updateUser = (req, _res, next) => {
- return validate(schemaUpdateUser, req.body, next);
- };
- module.exports.logIn = (req, _res, next) => {
- return validate(schemaLogIn, req.body, next);
- };
- module.exports.validateUploadFile = (req, res, next) => {
- if (!req.file)
- return res.status(400).json({
- status: 'error',
- code: 400,
- data: 'Bad request',
- message: 'File not found',
- });
- next();
- };
|