message.js 1.8 KB

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