messages.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const express = require('express');
  2. const router = express.Router();
  3. const guard = require('../helpers/guard');
  4. const controllers = require('../controllers/messages');
  5. const validation = require('../validation/message');
  6. const upload = require('../helpers/upload');
  7. router
  8. .get('/', guard, controllers.listMessages)
  9. .post('/', guard, validation.sentMessage, controllers.sentMessage)
  10. .post('/reply/', guard, validation.sentMessage, controllers.sentMessageReply)
  11. .post(
  12. '/forward/',
  13. guard,
  14. validation.sentForwardMessage,
  15. controllers.sentMessageForward
  16. )
  17. .patch(
  18. '/selected/',
  19. guard,
  20. validation.removeSelected,
  21. controllers.removeSelected
  22. )
  23. .patch('/unpin/all/', guard, validation.unpinAll, controllers.unpinAllMessage)
  24. .post(
  25. '/image/:companionIdAndCaption',
  26. [guard, upload.uploadImage.single('image'), validation.validateUploadFile],
  27. controllers.imageMessage
  28. )
  29. .post(
  30. '/audio/:companionIdAndCaption',
  31. [guard, upload.uploadAudio.single('audio'), validation.validateUploadFile],
  32. controllers.audioMessage
  33. )
  34. .post(
  35. '/video/:companionIdAndCaption',
  36. [guard, upload.uploadVideo.single('video'), validation.validateUploadFile],
  37. controllers.videoMessage
  38. )
  39. .post(
  40. '/file/:companionIdAndCaption',
  41. [guard, upload.uploadFile.single('file'), validation.validateUploadFile],
  42. controllers.fileMessage
  43. );
  44. router
  45. .get('/:companionId', guard, controllers.listMessagesById)
  46. .patch('/pin/:id', guard, controllers.updateMessagePin)
  47. .patch('/:id', guard, controllers.updateMessageEmoji)
  48. .delete('/:id', guard, controllers.removeMessage);
  49. module.exports = router;