message.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const Joi = require('joi');
  2. const validate = require('./validate');
  3. const schemaSentMessage = Joi.object({
  4. id: Joi.string().required(),
  5. message: Joi.string().min(1).max(1400).required(),
  6. caption: Joi.any().optional(),
  7. });
  8. const schemaSentForwardMessage = Joi.object({
  9. id: Joi.string().required(),
  10. companionIdForwardToAndFrom: Joi.any().required(),
  11. });
  12. const schemaRemoveSelected = Joi.object({
  13. companionId: Joi.string().required(),
  14. selectedArr: Joi.array().items(Joi.string().min(5).max(50)).required(),
  15. });
  16. const schemaUnpinAll = Joi.object({
  17. pinnedMessages: Joi.array().items(Joi.string().min(5).max(50)).required(),
  18. });
  19. module.exports.sentMessage = (req, _res, next) => {
  20. return validate(schemaSentMessage, req.body, next);
  21. };
  22. module.exports.sentForwardMessage = (req, _res, next) => {
  23. return validate(schemaSentForwardMessage, req.body, next);
  24. };
  25. module.exports.removeSelected = (req, _res, next) => {
  26. return validate(schemaRemoveSelected, req.body, next);
  27. };
  28. module.exports.unpinAll = (req, _res, next) => {
  29. return validate(schemaUnpinAll, req.body, next);
  30. };
  31. module.exports.validateUploadFile = (req, res, next) => {
  32. if (!req.file)
  33. return res.status(400).json({
  34. status: 'error',
  35. code: 400,
  36. data: 'Bad request',
  37. message: 'File not found',
  38. });
  39. next();
  40. };