This repository has been archived on 2026-05-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
chatless/backend/service-privateroom/routes/conversations.js
2021-05-30 20:55:00 +02:00

30 lines
No EOL
766 B
JavaScript

const router = require("express").Router();
const Conversation = require("../models/Conversation");
// new conv
router.post("/", async (req, res) => {
const newConversation = new Conversation({
members: [req.body.senderId, req.body.receiverId]
});
try{
const savedConversation = await newConversation.save();
res.status(200).json(savedConversation);
}catch (err){
res.status(500).json(err)
}
});
// get conv
router.get("/:userId", async (req, res) => {
try {
const conversation = await Conversation.find({
members: { $in: [req.params.userId] },
});
res.status(200).json(conversation);
}catch (err){
res.status(500).json(err)
}
})
module.exports = router;