Commit a0d39bde authored by Balasuriya D.A.M.'s avatar Balasuriya D.A.M.

Fetch Chat Message API-Create all API

parent bfe3ede7
......@@ -45,4 +45,18 @@ const sendMessage = asyncHandler(async (req, res) => {
}
});
module.exports = { sendMessage };
\ No newline at end of file
const allMessages = asyncHandler(async(req, res) => {
try {
const messages = await Message.find({ chat: req.params.chatId })
.populate("sender", "name pic email")
.populate("chat");
res.json(messages);
} catch (error) {
res.status(400);
throw new Error(error.message);
}
});
module.exports = { sendMessage, allMessages };
\ No newline at end of file
const express = require("express");
const { sendMessage } = require("../controllers/messageControllers");
const { sendMessage, allMessages } = require("../controllers/messageControllers");
const { protect } = require("../middleware/authMiddleware");
const router = express.Router();
router.route("/").post(protect, sendMessage);
//router.route("/:chatId").get(protect, allMessages);
router.route("/:chatId").get(protect, allMessages);
module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment