返回提交历史
Modified
src/controllers/dynamic/aggregateSessionsController.ts
+11
-4
Modified
src/managers/sessionManager.ts
+17
-1
Deleted
static/fixed_responses/aggregateSessions.json
+0
-3
XFEstudio/XFESpaceNinjaServer
feat: aggregateSessions (#3614)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3614 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
0e139dd1
代码差异
3 个文件
+28
-8
@@ -1,8 +1,15 @@
1
1
import type { RequestHandler } from "express";
2
import aggregateSessions from "../../../static/fixed_responses/aggregateSessions.json" with { type: "json" };
2
import { aggregateSessions } from "../../managers/sessionManager.ts";
3
3
4
const aggregateSessionsController: RequestHandler = (_req, res) => {
5
res.json(aggregateSessions);
4
export const aggregateSessionsController: RequestHandler = (_req, res) => {
5
res.json({
6
Results: aggregateSessions()
7
} satisfies IAggregateSessionsResponse);
6
8
};
7
9
8
export { aggregateSessionsController };
10
interface IAggregateSessionsResponse {
11
Results: {
12
gameModeId: number;
13
count: number;
14
}[];
15
}
@@ -139,6 +139,21 @@ function deleteSession(sessionId: string | Types.ObjectId): boolean {
139
139
return false;
140
140
}
141
141
142
function aggregateSessions(): { gameModeId: number; count: number }[] {
143
const result: { gameModeId: number; count: number }[] = [];
144
for (const session of sessions) {
145
if (session.freePublic != 0) {
146
const obj = result.find(x => x.gameModeId == session.gameModeId);
147
if (obj) {
148
obj.count += 1;
149
} else {
150
result.push({ gameModeId: session.gameModeId, count: 1 });
151
}
152
}
153
}
154
return result;
155
}
156
142
157
export {
143
158
createNewSession,
144
159
getAllSessions,
@@ -146,5 +161,6 @@ export {
146
161
getSessionByCreatorID,
147
162
updateSession,
148
163
deleteSession,
149
getSession
164
getSession,
165
aggregateSessions
150
166
};
@@ -1,3 +0,0 @@
1
{
2
"Results": []
3
}