12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- const Joi = require('joi');
- const validate = require('./validate');
- const schemaSentMessage = Joi.object({
- id: Joi.string().required(),
- message: Joi.string().min(1).max(1400).required(),
- caption: Joi.any().optional(),
- });
- const schemaSentForwardMessage = Joi.object({
- id: Joi.string().required(),
- companionIdForwardToAndFrom: Joi.any().required(),
- message: Joi.string().min(1).max(1400).required(),
- caption: Joi.any().optional(),
- });
- const schemaRemoveSelected = Joi.object({
- companionId: Joi.string().required(),
- selectedArr: Joi.array().items(Joi.string().min(5).max(50)).required(),
- });
- const schemaUnpinAll = Joi.object({
- pinnedMessages: Joi.array().items(Joi.string().min(5).max(50)).required(),
- });
- module.exports.sentMessage = (req, _res, next) => {
- return validate(schemaSentMessage, req.body, next);
- };
- module.exports.sentForwardMessage = (req, _res, next) => {
- return validate(schemaSentForwardMessage, req.body, next);
- };
- module.exports.removeSelected = (req, _res, next) => {
- return validate(schemaRemoveSelected, req.body, next);
- };
- module.exports.unpinAll = (req, _res, next) => {
- return validate(schemaUnpinAll, 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();
- };
|