messages.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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('/edit/', guard, validation.editMessage, controllers.editMessage)
  12. .post(
  13. '/forward/',
  14. guard,
  15. validation.sentForwardMessage,
  16. controllers.sentMessageForward
  17. )
  18. .patch(
  19. '/selected/',
  20. guard,
  21. validation.removeSelected,
  22. controllers.removeSelected
  23. )
  24. .patch('/unpin/all/', guard, validation.unpinAll, controllers.unpinAllMessage)
  25. .post(
  26. '/image/:companionIdAndCaption',
  27. [guard, upload.uploadImage.single('image'), validation.validateUploadFile],
  28. controllers.imageMessage
  29. )
  30. .post(
  31. '/audio/:companionIdAndCaption',
  32. [guard, upload.uploadAudio.single('audio'), validation.validateUploadFile],
  33. controllers.audioMessage
  34. )
  35. .post(
  36. '/video/:companionIdAndCaption',
  37. [guard, upload.uploadVideo.single('video'), validation.validateUploadFile],
  38. controllers.videoMessage
  39. )
  40. .post(
  41. '/file/:companionIdAndCaption',
  42. [guard, upload.uploadFile.single('file'), validation.validateUploadFile],
  43. controllers.fileMessage
  44. );
  45. router
  46. .get('/:companionId', guard, controllers.listMessagesById)
  47. .patch('/pin/:id', guard, controllers.updateMessagePin)
  48. .patch('/:id', guard, controllers.updateMessageEmoji)
  49. .delete('/:id', guard, controllers.removeMessage);
  50. module.exports = router;