1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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(),
- });
- const schemaUpdateCredentials = Joi.object({
- name: Joi.string().min(1).max(30).trim().required(),
- lastName: Joi.string().min(1).max(30).trim().required(),
- originalName: Joi.string().min(1).max(30).trim().required(),
- originalLastName: Joi.string().min(1).max(30).trim().required(),
- });
- const schemaUpdateUser = Joi.object({
- nightMode: Joi.boolean().optional(),
- silentMode: Joi.boolean().optional(),
- sort: Joi.boolean().optional(),
- }).min(1);
- const schemaLogIn = Joi.object({
- number: Joi.string().min(8).max(14).required(),
- code: Joi.string().min(3).max(12).required(),
- });
- module.exports.registration = (req, _res, next) => {
- return validate(schemaCreateNewUser, req.body, next);
- };
- module.exports.updateCredentials = (req, _res, next) => {
- return validate(schemaUpdateCredentials, 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();
- };
|