diff --git a/src/controllers/conversation.controller.js b/src/controllers/conversation.controller.js index 354a47c..e358f3a 100644 --- a/src/controllers/conversation.controller.js +++ b/src/controllers/conversation.controller.js @@ -221,6 +221,20 @@ exports.sendMessage = async (req, res, next) => { } }; +exports.getNbOfMessages = async (req, res, next) => { + try { + const conversationId = req.params.id; + Conversation.findOne({ _id: conversationId }) + .then(conversation => { + res.send({ nb_messages: conversation.nb_messages }); + }).catch((error) => { + next(error) + }); + } catch (error) { + next(error) + } +} + exports.deleteMessage = async (req, res, next) => { try { @@ -236,5 +250,4 @@ exports.sendVocal = async (req, res, next) => { } catch (error) { next(error) } -}; - +}; \ No newline at end of file diff --git a/src/routes/conversation.route.js b/src/routes/conversation.route.js index 6ec31dd..abaf6e9 100644 --- a/src/routes/conversation.route.js +++ b/src/routes/conversation.route.js @@ -13,7 +13,7 @@ router.post('/instant', verifyToken, conversationController.createInstantConvers router.post('/block', verifyToken, conversationController.BlockConversation); router.post('/unblock', verifyToken, conversationController.UnblockConversation); router.post('/report', verifyToken, conversationController.ReportConversation); - +router.get('/:id/nb_messages', verifyToken, conversationController.getNbOfMessages); // messages router.get('/message/:id', verifyToken, conversationController.getMessageConversation);