-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollers.js
More file actions
33 lines (28 loc) · 1.04 KB
/
controllers.js
File metadata and controls
33 lines (28 loc) · 1.04 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
const moment = require("moment/moment");
const redisClient = require("./redisClient.js");
async function createRoom(req, res) {
console.log("Route - createRoom");
const { roomId } = req.body;
try {
await redisClient.hSet(`${roomId}`, {
created: moment().toString(),
updated: moment().toString(),
});
res.status(201).json({ status: "success", message: "Room Created Successfully" });
} catch (err) {
console.log("Redis Set Error :: ", err);
res.status(500).json({ status: "error", message: "Internal Server Error" });
}
}
async function getCode(req, res) {
console.log("Route - getCode");
const { roomId } = req.params;
try {
const data = await redisClient.hGet("code_contents", roomId);
res.status(200).json({ status: "success", contents: data });
} catch (err) {
console.error("Redis Get Error:", err);
res.status(500).json({ status: "error", message: "Internal Server Error" });
}
}
module.exports = { createRoom, getCode };