messages.js 1.3 KB

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