diff --git a/server/src/lib/showcase-stats/evaluator.test.ts b/server/src/lib/showcase/evaluator.test.ts similarity index 100% rename from server/src/lib/showcase-stats/evaluator.test.ts rename to server/src/lib/showcase/evaluator.test.ts diff --git a/server/src/lib/showcase-stats/evaluator.ts b/server/src/lib/showcase/evaluator.ts similarity index 100% rename from server/src/lib/showcase-stats/evaluator.ts rename to server/src/lib/showcase/evaluator.ts diff --git a/server/src/lib/showcase-stats/get-related.ts b/server/src/lib/showcase/get-related.ts similarity index 100% rename from server/src/lib/showcase-stats/get-related.ts rename to server/src/lib/showcase/get-related.ts diff --git a/server/src/lib/showcase-stats/get-stats.test.ts b/server/src/lib/showcase/get-stats.test.ts similarity index 100% rename from server/src/lib/showcase-stats/get-stats.test.ts rename to server/src/lib/showcase/get-stats.test.ts diff --git a/server/src/lib/showcase-stats/get-stats.ts b/server/src/lib/showcase/get-stats.ts similarity index 100% rename from server/src/lib/showcase-stats/get-stats.ts rename to server/src/lib/showcase/get-stats.ts 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 index 61909049c..e59954f99 100644 --- 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 @@ -20,7 +20,7 @@ import pbsRouter from "./pbs/router"; import sessionsRouter from "./sessions/router"; import foldersFolderIDRouter from "./folders/_folderID/router"; import tablesRouter from "./tables/router"; -import statsRouter from "./stats/router"; +import showcaseRouter from "./showcase/router"; import settingsRouter from "./settings/router"; const router: Router = Router({ mergeParams: true }); @@ -404,7 +404,7 @@ router.get("/leaderboard-adjacent", async (req, res) => { router.use("/pbs", pbsRouter); router.use("/sessions", sessionsRouter); router.use("/tables", tablesRouter); -router.use("/stats", statsRouter); +router.use("/showcase", showcaseRouter); router.use("/settings", settingsRouter); router.use("/folders/:folderID", foldersFolderIDRouter); diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/stats/router.test.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/showcase/router.test.ts similarity index 82% rename from server/src/server/router/api/v1/users/_userID/games/_game/_playtype/stats/router.test.ts rename to server/src/server/router/api/v1/users/_userID/games/_game/_playtype/showcase/router.test.ts index 8b40e100f..a3fd770a3 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/stats/router.test.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/showcase/router.test.ts @@ -42,9 +42,9 @@ t.beforeEach(async () => { await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {})); }); -t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats", (t) => { +t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => { t.test("Should return the evaluated stats for this user.", async (t) => { - const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/stats"); + const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/showcase"); t.hasStrict(res.body.body, [ { @@ -95,7 +95,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats", (t) => { id: 2, } as PrivateUserDocument); - const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/stats?projectUser=2"); + const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/showcase?projectUser=2"); t.hasStrict(res.body.body, [ { @@ -113,7 +113,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats", (t) => { }); t.test("Should return 404 if the user has not played this game.", async (t) => { - const res = await mockApi.get("/api/v1/users/1/games/bms/7K/stats"); + const res = await mockApi.get("/api/v1/users/1/games/bms/7K/showcase"); t.equal(res.statusCode, 404); @@ -125,10 +125,10 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats", (t) => { t.end(); }); -t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => { +t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase/custom", (t) => { t.test("Should return a custom folder evaluated stat on a user.", async (t) => { const res = await mockApi.get( - `/api/v1/users/1/games/iidx/SP/stats/custom?mode=folder&prop=grade>e=3&folderID=${TestingIIDXFolderSP10.folderID}` + `/api/v1/users/1/games/iidx/SP/showcase/custom?mode=folder&prop=grade>e=3&folderID=${TestingIIDXFolderSP10.folderID}` ); t.strictSame(res.body.body, { @@ -141,7 +141,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => { t.test("Should return a custom chart evaluated stat on a user.", async (t) => { const res = await mockApi.get( - `/api/v1/users/1/games/iidx/SP/stats/custom?mode=chart&prop=grade&chartID=${Testing511SPA.chartID}` + `/api/v1/users/1/games/iidx/SP/showcase/custom?mode=chart&prop=grade&chartID=${Testing511SPA.chartID}` ); t.strictSame(res.body.body, { @@ -153,13 +153,13 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => { t.test("Should reject for invalid folderID.", async (t) => { const res = await mockApi.get( - `/api/v1/users/1/games/iidx/SP/stats/custom?mode=folder&prop=grade>e=4` + `/api/v1/users/1/games/iidx/SP/showcase/custom?mode=folder&prop=grade>e=4` ); t.equal(res.statusCode, 400, "Should reject for no folderID"); const res2 = await mockApi.get( - `/api/v1/users/1/games/iidx/SP/stats/custom?mode=folder&prop=grade>e=4&folderID=foo&folderID=bar` + `/api/v1/users/1/games/iidx/SP/showcase/custom?mode=folder&prop=grade>e=4&folderID=foo&folderID=bar` ); t.equal(res2.statusCode, 400, "Should reject for non-string folderID"); @@ -169,13 +169,13 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => { t.test("Should reject for invalid chartID.", async (t) => { const res = await mockApi.get( - `/api/v1/users/1/games/iidx/SP/stats/custom?mode=chart&prop=grade>e=4` + `/api/v1/users/1/games/iidx/SP/showcase/custom?mode=chart&prop=grade>e=4` ); t.equal(res.statusCode, 400, "Should reject for no chartID"); const res2 = await mockApi.get( - `/api/v1/users/1/games/iidx/SP/stats/custom?mode=chart&prop=grade&chartID=foo&chartID=bar` + `/api/v1/users/1/games/iidx/SP/showcase/custom?mode=chart&prop=grade&chartID=foo&chartID=bar` ); t.equal(res2.statusCode, 400, "Should reject for non-string chartID"); @@ -185,7 +185,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => { t.test("Should reject for invalid mode", async (t) => { const res = await mockApi.get( - `/api/v1/users/1/games/iidx/SP/stats/custom?mode=nonsense&prop=grade>e=4&chartID=foo` + `/api/v1/users/1/games/iidx/SP/showcase/custom?mode=nonsense&prop=grade>e=4&chartID=foo` ); t.equal(res.statusCode, 400); @@ -197,7 +197,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/stats/custom", (t) => { }); // @todo #239 PUT UGPT-Stats needs some tests for input validation. -t.test("PUT /api/v1/users/:userID/games/:game/:playtype/stats", (t) => { +t.test("PUT /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => { t.test("Requires the user to be authed as the requested user.", async (t) => { await db["api-tokens"].insert({ userID: 2, @@ -209,7 +209,7 @@ t.test("PUT /api/v1/users/:userID/games/:game/:playtype/stats", (t) => { }); const res = await mockApi - .put("/api/v1/users/1/games/iidx/SP/stats") + .put("/api/v1/users/1/games/iidx/SP/showcase") .set("Authorization", `Bearer alt_token`); t.equal(res.statusCode, 403); @@ -228,7 +228,7 @@ t.test("PUT /api/v1/users/:userID/games/:game/:playtype/stats", (t) => { }); const res = await mockApi - .put("/api/v1/users/1/games/iidx/SP/stats") + .put("/api/v1/users/1/games/iidx/SP/showcase") .set("Authorization", `Bearer alt_token`); t.equal(res.statusCode, 403); @@ -247,7 +247,7 @@ t.test("PUT /api/v1/users/:userID/games/:game/:playtype/stats", (t) => { }); const res = await mockApi - .put("/api/v1/users/1/games/iidx/SP/stats") + .put("/api/v1/users/1/games/iidx/SP/showcase") .set("Authorization", `Bearer alt_token`) .send([ { diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/stats/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/showcase/router.ts similarity index 86% rename from server/src/server/router/api/v1/users/_userID/games/_game/_playtype/stats/router.ts rename to server/src/server/router/api/v1/users/_userID/games/_game/_playtype/showcase/router.ts index bad458c90..e630f96ec 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/stats/router.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/showcase/router.ts @@ -1,15 +1,15 @@ import { Router } from "express"; -import { SYMBOL_TachiData } from "../../../../../../../../../../lib/constants/tachi"; -import { EvaluateUsersStatsShowcase } from "../../../../../../../../../../lib/showcase-stats/get-stats"; -import { ResolveUser } from "../../../../../../../../../../utils/user"; +import { SYMBOL_TachiData } from "lib/constants/tachi"; +import { EvaluateUsersStatsShowcase } from "lib/showcase/get-stats"; +import { ResolveUser } from "utils/user"; import p from "prudence"; -import { FormatPrError } from "../../../../../../../../../../utils/prudence"; +import { FormatPrError } from "utils/prudence"; import { ShowcaseStatDetails, GetGamePTConfig } from "tachi-common"; -import { EvaluateShowcaseStat } from "../../../../../../../../../../lib/showcase-stats/evaluator"; -import db from "../../../../../../../../../../external/mongo/db"; -import { RequirePermissions } from "../../../../../../../../../middleware/auth"; -import { RequireAuthedAsUser } from "../../../../middleware"; -import { GetRelatedStatDocuments } from "lib/showcase-stats/get-related"; +import { EvaluateShowcaseStat } from "lib/showcase/evaluator"; +import db from "external/mongo/db"; +import { RequirePermissions } from "server/middleware/auth"; +import { RequireAuthedAsUser } from "server/router/api/v1/users/_userID/middleware"; +import { GetRelatedStatDocuments } from "lib/showcase/get-related"; const router: Router = Router({ mergeParams: true }); /** @@ -17,7 +17,7 @@ const router: Router = Router({ mergeParams: true }); * * @param projectUser - Project another user's stats instead of their set stats. * - * @name GET /api/v1/users/:userID/games/:game/:playtype/stats + * @name GET /api/v1/users/:userID/games/:game/:playtype/showcase */ router.get("/", async (req, res) => { const user = req[SYMBOL_TachiData]!.requestedUser!; @@ -59,7 +59,7 @@ router.get("/", async (req, res) => { * @TODO: #237 This custom stat code accepts charts and folders from any game and any playtype - technically, * this is breaking rest quite painfully! * - * @name GET /api/v1/users/:userID/games/:game/:playtype/stats/custom + * @name GET /api/v1/users/:userID/games/:game/:playtype/showcase/custom */ router.get("/custom", async (req, res) => { const user = req[SYMBOL_TachiData]!.requestedUser!; @@ -141,7 +141,7 @@ router.get("/custom", async (req, res) => { /** * Replaces a user's preferred stats. * - * @name PUT /api/v1/users/:userID/games/:game/:playtype/stats + * @name PUT /api/v1/users/:userID/games/:game/:playtype/showcase */ router.put("/", RequireAuthedAsUser, RequirePermissions("customise_profile"), async (req, res) => {