-
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathroomController.js
More file actions
54 lines (47 loc) · 1.65 KB
/
roomController.js
File metadata and controls
54 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const Room = require('../models/Room');
const createRoom = async (req, res) => {
const { roomName } = req.body;
if (!roomName ) return res.status(400).json({ msg: "Enter all Fields" });
try {
// add the user who has created this room automatically
// const user = req.user;
const newRoom = await Room.create({ roomName })
return res.status(200).json({ newRoom })
} catch (err) {
console.log(err);
res.status(500).json({ msg: "Error in creating room" });
}
}
const joinRoom = async (req, res) => {
const { roomId } = req.body;
try {
//const user = req.user;
const room = await Room.findById({ _id: roomId })
if (!room) return res.status(404).json({ msg: "Room not found" });
return res.status(200).json({ room });
} catch (err) {
console.log(err);
res.status(400).json({ msg: "Error in joining room" });
}
}
const getAllRoom=async(req,res)=>{
try {
const rooms = await Room.find({}).sort({ createdAt: -1 });;
return res.status(200).json({ rooms });
} catch (err) {
console.log(err);
res.status(400).json({ msg: "Error in getting all rooms" });
}
}
const getRoomById=async(req,res)=>{
try{
const {id,language}=req.query
const room=await Room.findOne({_id:id,language:language});
if(!room) return res.status(404).json({ msg: "Room not found" });
return res.status(200).json({ room });
}catch(err){
console.log(err);
res.status(400).json({ msg: "Error in getting room by id" });
}
}
module.exports = { joinRoom, createRoom,getAllRoom,getRoomById }