From b6ea9107e83e2e10460093db96ec4f57dfe7381d Mon Sep 17 00:00:00 2001 From: inmake Date: Mon, 17 Jun 2024 18:15:41 +0500 Subject: [PATCH] upd --- src/models/ActiveSession.ts | 3 +++ src/routes/activeSession.ts | 26 ++++++++++++++------------ src/routes/getCountryCode.ts | 4 +--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/models/ActiveSession.ts b/src/models/ActiveSession.ts index 44bac79..20cbfda 100644 --- a/src/models/ActiveSession.ts +++ b/src/models/ActiveSession.ts @@ -37,6 +37,9 @@ const activeSessionSchema = new Schema( connectedPlayersCount: { type: Number, }, + endAt: { + type: Date, + }, }, { timestamps: true, diff --git a/src/routes/activeSession.ts b/src/routes/activeSession.ts index 447e0da..8ff8aa7 100644 --- a/src/routes/activeSession.ts +++ b/src/routes/activeSession.ts @@ -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(), + }); + + 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; diff --git a/src/routes/getCountryCode.ts b/src/routes/getCountryCode.ts index 4f43732..9158f8a 100644 --- a/src/routes/getCountryCode.ts +++ b/src/routes/getCountryCode.ts @@ -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 }); } });