From fdd4945369c366c5ee0f61b3dff29993108930eb Mon Sep 17 00:00:00 2001 From: zkldi Date: Wed, 16 Jun 2021 20:01:28 +0100 Subject: [PATCH] mounting the API would be a good start... --- server/src/server/router/api/v1/router.ts | 2 ++ .../games/_game/_playtype}/middleware.ts | 0 .../games/_game/_playtype/router.test.ts | 20 +++++++++++++++++++ .../games/_game/_playtype}/router.ts | 0 .../users/{!userID => _userID}/middleware.ts | 0 .../v1/users/{!userID => _userID}/router.ts | 3 +++ .../src/server/router/api/v1/users/router.ts | 2 +- 7 files changed, 26 insertions(+), 1 deletion(-) rename server/src/server/router/api/v1/users/{!userID/games/!game/!playtype => _userID/games/_game/_playtype}/middleware.ts (100%) create mode 100644 server/src/server/router/api/v1/users/_userID/games/_game/_playtype/router.test.ts rename server/src/server/router/api/v1/users/{!userID/games/!game/!playtype => _userID/games/_game/_playtype}/router.ts (100%) rename server/src/server/router/api/v1/users/{!userID => _userID}/middleware.ts (100%) rename server/src/server/router/api/v1/users/{!userID => _userID}/router.ts (91%) diff --git a/server/src/server/router/api/v1/router.ts b/server/src/server/router/api/v1/router.ts index 2f669d542..33c9071ca 100644 --- a/server/src/server/router/api/v1/router.ts +++ b/server/src/server/router/api/v1/router.ts @@ -2,12 +2,14 @@ import { Router } from "express"; import authRouter from "./auth/router"; import importRouter from "./import/router"; import statusRouter from "./status/router"; +import usersRouter from "./users/router"; const router: Router = Router({ mergeParams: true }); router.use("/auth", authRouter); router.use("/status", statusRouter); router.use("/import", importRouter); +router.use("/users", usersRouter); router.all("*", (req, res) => res.status(404).json({ diff --git a/server/src/server/router/api/v1/users/!userID/games/!game/!playtype/middleware.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/middleware.ts similarity index 100% rename from server/src/server/router/api/v1/users/!userID/games/!game/!playtype/middleware.ts rename to server/src/server/router/api/v1/users/_userID/games/_game/_playtype/middleware.ts diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/router.test.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/router.test.ts new file mode 100644 index 000000000..f8914ea69 --- /dev/null +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/router.test.ts @@ -0,0 +1,20 @@ +import t from "tap"; +import { CloseAllConnections } from "../../../../../../../../../test-utils/close-connections"; +import mockApi from "../../../../../../../../../test-utils/mock-api"; +import ResetDBState from "../../../../../../../../../test-utils/resets"; + +t.test("GET /api/v1/users/:userID/games/:game/:playtype/", (t) => { + t.beforeEach(ResetDBState); + + t.test("Should return a users statistics for that game.", async (t) => { + const res = await mockApi.get("/api/v1/users/zkldi/games/iidx/SP"); + + t.strictSame(res.body, {}); + + t.end(); + }); + + t.end(); +}); + +t.teardown(CloseAllConnections); diff --git a/server/src/server/router/api/v1/users/!userID/games/!game/!playtype/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/router.ts similarity index 100% rename from server/src/server/router/api/v1/users/!userID/games/!game/!playtype/router.ts rename to server/src/server/router/api/v1/users/_userID/games/_game/_playtype/router.ts diff --git a/server/src/server/router/api/v1/users/!userID/middleware.ts b/server/src/server/router/api/v1/users/_userID/middleware.ts similarity index 100% rename from server/src/server/router/api/v1/users/!userID/middleware.ts rename to server/src/server/router/api/v1/users/_userID/middleware.ts diff --git a/server/src/server/router/api/v1/users/!userID/router.ts b/server/src/server/router/api/v1/users/_userID/router.ts similarity index 91% rename from server/src/server/router/api/v1/users/!userID/router.ts rename to server/src/server/router/api/v1/users/_userID/router.ts index 7d6195f77..4f51a1aff 100644 --- a/server/src/server/router/api/v1/users/!userID/router.ts +++ b/server/src/server/router/api/v1/users/_userID/router.ts @@ -2,6 +2,7 @@ import { Router } from "express"; import db from "../../../../../../external/mongo/db"; import { SYMBOL_TachiData } from "../../../../../../lib/constants/tachi"; import { GetUserFromParam } from "./middleware"; +import gamePTRouter from "./games/_game/_playtype/router"; const router: Router = Router({ mergeParams: true }); @@ -40,4 +41,6 @@ router.get("/stats", async (req, res) => { }); }); +router.use("/games/:game/:playtype", gamePTRouter); + export default router; diff --git a/server/src/server/router/api/v1/users/router.ts b/server/src/server/router/api/v1/users/router.ts index cb78cb4a2..08e12b1cf 100644 --- a/server/src/server/router/api/v1/users/router.ts +++ b/server/src/server/router/api/v1/users/router.ts @@ -1,6 +1,6 @@ import { Router } from "express"; import db from "../../../../../external/mongo/db"; -import userIDRouter from "./!userID/router"; +import userIDRouter from "./_userID/router"; const router: Router = Router({ mergeParams: true });