message.js 1.4 KB

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