upd
This commit is contained in:
@@ -37,6 +37,9 @@ const activeSessionSchema = new Schema(
|
|||||||
connectedPlayersCount: {
|
connectedPlayersCount: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
endAt: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
|
|||||||
+14
-12
@@ -1,24 +1,26 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import ActiveSession from "../models/ActiveSession";
|
import ActiveSession from "../models/ActiveSession";
|
||||||
import { isValidObjectId } from "mongoose";
|
// import { isValidObjectId } from "mongoose";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/:id", async (req, res) => {
|
router.get("/:id", async (req, res) => {
|
||||||
const activeSessionId = req.params.id;
|
const activeSessionId = req.params.id;
|
||||||
|
|
||||||
if (!isValidObjectId(activeSessionId)) {
|
// if (!isValidObjectId(activeSessionId)) {
|
||||||
return res.json({ status: "error", message: "Invalid ObjectId" });
|
// return res.json({ status: "error", message: "Invalid ObjectId" });
|
||||||
|
// }
|
||||||
|
|
||||||
|
try {
|
||||||
|
const activeSession = await ActiveSession.findById(activeSessionId);
|
||||||
|
await ActiveSession.findByIdAndUpdate(activeSessionId, {
|
||||||
|
updatedAt: new Date(),
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json(activeSession);
|
||||||
|
} catch (error) {
|
||||||
|
res.json({ error: (error as Error).message });
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeSession = await ActiveSession.findById(activeSessionId);
|
|
||||||
await ActiveSession.findByIdAndUpdate(activeSessionId, {
|
|
||||||
updatedAt: new Date(),
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("activeSession", activeSession);
|
|
||||||
|
|
||||||
res.json(activeSession);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const activeSessionRouter = router;
|
const activeSessionRouter = router;
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ router.get("/", async (req, res) => {
|
|||||||
|
|
||||||
res.json({ countryCode });
|
res.json({ countryCode });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
res.json({ error: (error as Error).message });
|
||||||
res.json({ error: error.message });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user