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";
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2024-01-06 16:26:58 +01:00
|
|
|
//TODO: cleanup
|
2023-05-19 15:22:48 -03:00
|
|
|
const findSessionsController: RequestHandler = (_req, res) => {
|
2024-06-24 12:37:28 +02:00
|
|
|
const reqBody = JSON.parse(String(_req.body));
|
2024-01-06 16:26:58 +01:00
|
|
|
logger.debug("FindSession Request ", { reqBody });
|
2024-06-24 12:37:28 +02:00
|
|
|
const req = JSON.parse(String(_req.body));
|
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-06-24 12:37:28 +02:00
|
|
|
const session = getSession(req.id as string);
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2023-06-03 19:24:57 -07:00
|
|
|
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
|
|
|
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-06-24 12:37:28 +02:00
|
|
|
const session = getSession(req.originalSessionId as string);
|
2023-06-03 19:24:57 -07:00
|
|
|
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
|
|
|
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-06-24 12:37:28 +02:00
|
|
|
const session = getSession(String(_req.body));
|
2023-06-03 19:24:57 -07:00
|
|
|
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
|
|
|
else res.json({});
|
|
|
|
}
|
2023-05-19 15:22:48 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
export { findSessionsController };
|