This commit is contained in:
2024-06-17 18:15:41 +05:00
parent 201c96e219
commit b6ea9107e8
3 changed files with 18 additions and 15 deletions
+3
View File
@@ -37,6 +37,9 @@ const activeSessionSchema = new Schema(
connectedPlayersCount: {
type: Number,
},
endAt: {
type: Date,
},
},
{
timestamps: true,
+8 -6
View File
@@ -1,24 +1,26 @@
import { Router } from "express";
import ActiveSession from "../models/ActiveSession";
import { isValidObjectId } from "mongoose";
// import { isValidObjectId } from "mongoose";
const router = Router();
router.get("/:id", async (req, res) => {
const activeSessionId = req.params.id;
if (!isValidObjectId(activeSessionId)) {
return res.json({ status: "error", message: "Invalid ObjectId" });
}
// if (!isValidObjectId(activeSessionId)) {
// return res.json({ status: "error", message: "Invalid ObjectId" });
// }
try {
const activeSession = await ActiveSession.findById(activeSessionId);
await ActiveSession.findByIdAndUpdate(activeSessionId, {
updatedAt: new Date(),
});
console.log("activeSession", activeSession);
res.json(activeSession);
} catch (error) {
res.json({ error: (error as Error).message });
}
});
const activeSessionRouter = router;
+1 -3
View File
@@ -18,9 +18,7 @@ router.get("/", async (req, res) => {
res.json({ countryCode });
} catch (error) {
if (error instanceof Error) {
res.json({ error: error.message });
}
res.json({ error: (error as Error).message });
}
});