message.js 1.6 KB

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