forked from OpenWF/SpaceNinjaServer
chore: improve IFindSessionRequest (#652)
This commit is contained in:
parent
44b78ecfe8
commit
8a4f2f4d0e
@ -1,31 +1,28 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getSession } from "@/src/managers/sessionManager";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { IFindSessionRequest } from "@/src/types/session";
|
||||
|
||||
//TODO: cleanup
|
||||
const findSessionsController: RequestHandler = (_req, res) => {
|
||||
const reqBody = JSON.parse(String(_req.body));
|
||||
logger.debug("FindSession Request ", { reqBody });
|
||||
const req = JSON.parse(String(_req.body));
|
||||
export const findSessionsController: RequestHandler = (_req, res) => {
|
||||
const req = JSON.parse(String(_req.body)) as IFindSessionRequest;
|
||||
logger.debug("FindSession Request ", req);
|
||||
if (req.id != undefined) {
|
||||
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 });
|
||||
else res.json({});
|
||||
} else if (req.originalSessionId != undefined) {
|
||||
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 });
|
||||
else res.json({});
|
||||
} else {
|
||||
logger.debug("Found SessionRequest");
|
||||
|
||||
const session = getSession(String(_req.body));
|
||||
const session = getSession(req);
|
||||
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
||||
else res.json({});
|
||||
}
|
||||
};
|
||||
|
||||
export { findSessionsController };
|
||||
|
@ -44,7 +44,6 @@ function getSessionByID(sessionId: string): ISession | undefined {
|
||||
return sessions.find(session => session.sessionId === sessionId);
|
||||
}
|
||||
|
||||
//TODO: proper typings
|
||||
function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
||||
if (typeof sessionIdOrRequest === "string") {
|
||||
const session = sessions.find(session => session.sessionId === sessionIdOrRequest);
|
||||
@ -63,7 +62,11 @@ function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
||||
const request = sessionIdOrRequest;
|
||||
const matchingSessions = sessions.filter(session => {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export interface ISession {
|
||||
sessionId: string;
|
||||
creatorId: string;
|
||||
@ -28,5 +27,14 @@ export interface ISession {
|
||||
}
|
||||
|
||||
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