1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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 schemaEditMessage = Joi.object({
- id: Joi.string().required(),
- message: Joi.any().optional(),
- 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.editMessage = (req, _res, next) => {
- return validate(schemaEditMessage, 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();
- };
|