2023-05-19 15:22:48 -03:00
|
|
|
import { RequestHandler } from "express";
|
2023-06-03 19:24:57 -07:00
|
|
|
import { getSession } from "@/src/managers/sessionManager";
|
2024-01-06 16:26:58 +01:00
|
|
|
import { logger } from "@/src/utils/logger";
|
2024-12-29 21:40:25 +01:00
|
|
|
import { IFindSessionRequest } from "@/src/types/session";
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2024-12-29 21:40:25 +01:00
|
|
|
export const findSessionsController: RequestHandler = (_req, res) => {
|
|
|
|
const req = JSON.parse(String(_req.body)) as IFindSessionRequest;
|
|
|
|
logger.debug("FindSession Request ", req);
|
2023-06-03 19:24:57 -07:00
|
|
|
if (req.id != undefined) {
|
2024-01-06 16:26:58 +01:00
|
|
|
logger.debug("Found ID");
|
2024-12-29 21:40:25 +01:00
|
|
|
const session = getSession(req.id);
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2025-01-20 12:21:39 +01:00
|
|
|
if (session.length) res.json({ queryId: req.queryId, Sessions: session });
|
2023-06-03 19:24:57 -07:00
|
|
|
else res.json({});
|
|
|
|
} else if (req.originalSessionId != undefined) {
|
2024-01-06 16:26:58 +01:00
|
|
|
logger.debug("Found OriginalSessionID");
|
2023-06-03 19:24:57 -07:00
|
|
|
|
2024-12-29 21:40:25 +01:00
|
|
|
const session = getSession(req.originalSessionId);
|
2025-01-20 12:21:39 +01:00
|
|
|
if (session.length) res.json({ queryId: req.queryId, Sessions: session });
|
2023-06-03 19:24:57 -07:00
|
|
|
else res.json({});
|
|
|
|
} else {
|
2024-01-06 16:26:58 +01:00
|
|
|
logger.debug("Found SessionRequest");
|
2023-06-03 19:24:57 -07:00
|
|
|
|
2024-12-29 21:40:25 +01:00
|
|
|
const session = getSession(req);
|
2025-01-20 12:21:39 +01:00
|
|
|
if (session.length) res.json({ queryId: req.queryId, Sessions: session });
|
2023-06-03 19:24:57 -07:00
|
|
|
else res.json({});
|
|
|
|
}
|
2023-05-19 15:22:48 -03:00
|
|
|
};
|