chore: improve IFindSessionRequest #652
@ -1,31 +1,28 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { getSession } from "@/src/managers/sessionManager";
|
import { getSession } from "@/src/managers/sessionManager";
|
||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
|
import { IFindSessionRequest } from "@/src/types/session";
|
||||||
|
|
||||||
//TODO: cleanup
|
export const findSessionsController: RequestHandler = (_req, res) => {
|
||||||
const findSessionsController: RequestHandler = (_req, res) => {
|
const req = JSON.parse(String(_req.body)) as IFindSessionRequest;
|
||||||
const reqBody = JSON.parse(String(_req.body));
|
logger.debug("FindSession Request ", req);
|
||||||
logger.debug("FindSession Request ", { reqBody });
|
|
||||||
const req = JSON.parse(String(_req.body));
|
|
||||||
if (req.id != undefined) {
|
if (req.id != undefined) {
|
||||||
logger.debug("Found ID");
|
logger.debug("Found ID");
|
||||||
const session = getSession(req.id as string);
|
const session = getSession(req.id);
|
||||||
|
|
||||||
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
||||||
else res.json({});
|
else res.json({});
|
||||||
} else if (req.originalSessionId != undefined) {
|
} else if (req.originalSessionId != undefined) {
|
||||||
logger.debug("Found OriginalSessionID");
|
logger.debug("Found OriginalSessionID");
|
||||||
|
|
||||||
const session = getSession(req.originalSessionId as string);
|
const session = getSession(req.originalSessionId);
|
||||||
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
||||||
else res.json({});
|
else res.json({});
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Found SessionRequest");
|
logger.debug("Found SessionRequest");
|
||||||
|
|
||||||
const session = getSession(String(_req.body));
|
const session = getSession(req);
|
||||||
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
||||||
else res.json({});
|
else res.json({});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { findSessionsController };
|
|
||||||
|
@ -44,7 +44,6 @@ function getSessionByID(sessionId: string): ISession | undefined {
|
|||||||
return sessions.find(session => session.sessionId === sessionId);
|
return sessions.find(session => session.sessionId === sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: proper typings
|
|
||||||
function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
||||||
if (typeof sessionIdOrRequest === "string") {
|
if (typeof sessionIdOrRequest === "string") {
|
||||||
const session = sessions.find(session => session.sessionId === sessionIdOrRequest);
|
const session = sessions.find(session => session.sessionId === sessionIdOrRequest);
|
||||||
@ -63,7 +62,11 @@ function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
|||||||
const request = sessionIdOrRequest;
|
const request = sessionIdOrRequest;
|
||||||
const matchingSessions = sessions.filter(session => {
|
const matchingSessions = sessions.filter(session => {
|
||||||
for (const key in request) {
|
for (const key in request) {
|
||||||
if (key !== "eloRating" && key !== "queryId" && request[key] !== session[key as keyof ISession]) {
|
if (
|
||||||
|
key !== "eloRating" &&
|
||||||
|
key !== "queryId" &&
|
||||||
|
request[key as keyof IFindSessionRequest] !== session[key as keyof ISession]
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
export interface ISession {
|
export interface ISession {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
creatorId: string;
|
creatorId: string;
|
||||||
@ -28,5 +27,14 @@ export interface ISession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IFindSessionRequest {
|
export interface IFindSessionRequest {
|
||||||
[key: string]: any;
|
id?: string;
|
||||||
|
originalSessionId?: string;
|
||||||
|
buildId?: number;
|
||||||
|
gameModeId?: number;
|
||||||
|
regionId?: number;
|
||||||
|
maxEloDifference?: number;
|
||||||
|
eloRating?: number;
|
||||||
|
enforceElo?: boolean;
|
||||||
|
xplatform?: boolean;
|
||||||
|
queryId?: number;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user