From e61bfad70fb03a06cfb215bbaf30602518daba7c Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:57:31 +0100 Subject: [PATCH] Organise Imports --- .../import-types/common/api-kai/iidx/converter.ts | 2 +- .../common/batch-manual/converter.test.ts | 2 +- .../import-types/common/batch-manual/converter.ts | 4 ++-- .../common/batch-manual/parser.test.ts | 2 +- .../import-types/common/batch-manual/parser.ts | 2 +- server/src/server/middleware/auth.ts | 4 ++-- server/src/server/middleware/multer-upload.ts | 6 +++--- .../server/middleware/prudence-validate.test.ts | 4 ++-- server/src/server/middleware/prudence-validate.ts | 12 ++++++------ server/src/server/middleware/request-logger.ts | 2 +- .../src/server/middleware/sanitise-qstring.test.ts | 4 ++-- server/src/server/router/api/v1/auth/auth.ts | 8 ++++---- .../games/_game/_playtype/sessions/router.ts | 14 +++++--------- .../games/_game/_playtype/settings/router.ts | 1 - .../games/_game/_playtype/targets/router.ts | 2 +- server/src/server/router/ir/router.ts | 2 +- server/src/test-utils/mock-api.ts | 5 ++--- server/src/test-utils/server.ts | 2 +- 18 files changed, 36 insertions(+), 42 deletions(-) diff --git a/server/src/lib/score-import/import-types/common/api-kai/iidx/converter.ts b/server/src/lib/score-import/import-types/common/api-kai/iidx/converter.ts index d3734f9e2..f5a5dbc43 100644 --- a/server/src/lib/score-import/import-types/common/api-kai/iidx/converter.ts +++ b/server/src/lib/score-import/import-types/common/api-kai/iidx/converter.ts @@ -1,5 +1,5 @@ import p from "prudence"; -import { Lamps, integer } from "tachi-common"; +import { integer, Lamps } from "tachi-common"; import { FormatPrError } from "utils/prudence"; import { FindIIDXChartOnInGameIDVersion } from "utils/queries/charts"; import { FindSongOnID } from "utils/queries/songs"; diff --git a/server/src/lib/score-import/import-types/common/batch-manual/converter.test.ts b/server/src/lib/score-import/import-types/common/batch-manual/converter.test.ts index fb85d3e98..5ab5b0d59 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/converter.test.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/converter.test.ts @@ -1,6 +1,6 @@ import deepmerge from "deepmerge"; import CreateLogCtx from "lib/logger/logger"; -import { Game, BatchManualScore } from "tachi-common"; +import { BatchManualScore, Game } from "tachi-common"; import t from "tap"; import ResetDBState from "test-utils/resets"; import { GetKTDataJSON, Testing511Song, Testing511SPA } from "test-utils/test-data"; diff --git a/server/src/lib/score-import/import-types/common/batch-manual/converter.ts b/server/src/lib/score-import/import-types/common/batch-manual/converter.ts index 8256c82f1..fa5be9fea 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/converter.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/converter.ts @@ -3,10 +3,10 @@ import { KtLogger } from "lib/logger/logger"; import { BatchManualScore, ChartDocument, - ImportTypes, - SongDocument, Grades, IDStrings, + ImportTypes, + SongDocument, } from "tachi-common"; import { FindBMSChartOnHash, diff --git a/server/src/lib/score-import/import-types/common/batch-manual/parser.test.ts b/server/src/lib/score-import/import-types/common/batch-manual/parser.test.ts index 584bc34ad..f954066f0 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/parser.test.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/parser.test.ts @@ -1,9 +1,9 @@ import deepmerge from "deepmerge"; +import { IIDXDans } from "lib/constants/classes"; import CreateLogCtx from "lib/logger/logger"; import { BatchManual } from "tachi-common"; import t from "tap"; import { EscapeStringRegexp } from "utils/misc"; -import { IIDXDans } from "lib/constants/classes"; import ScoreImportFatalError from "../../../framework/score-importing/score-import-error"; import { ParseBatchManualFromObject as ParserFn } from "./parser"; diff --git a/server/src/lib/score-import/import-types/common/batch-manual/parser.ts b/server/src/lib/score-import/import-types/common/batch-manual/parser.ts index 9efbcdbef..0850b442c 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/parser.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/parser.ts @@ -1,4 +1,5 @@ import deepmerge from "deepmerge"; +import { IIDXDans, SDVXDans, WACCA_STAGEUPS } from "lib/constants/classes"; import { KtLogger } from "lib/logger/logger"; import { TachiConfig } from "lib/setup/config"; import p, { PrudenceSchema, ValidSchemaValue } from "prudence"; @@ -12,7 +13,6 @@ import { Playtypes, } from "tachi-common"; import { FormatPrError } from "utils/prudence"; -import { IIDXDans, SDVXDans, WACCA_STAGEUPS } from "lib/constants/classes"; import ScoreImportFatalError from "../../../framework/score-importing/score-import-error"; import { ParserFunctionReturns } from "../types"; import { BatchManualContext } from "./types"; diff --git a/server/src/server/middleware/auth.ts b/server/src/server/middleware/auth.ts index 9685b55f3..84a606983 100644 --- a/server/src/server/middleware/auth.ts +++ b/server/src/server/middleware/auth.ts @@ -1,10 +1,10 @@ import { RequestHandler } from "express"; import db from "external/mongo/db"; import { SYMBOL_TachiAPIAuth } from "lib/constants/tachi"; -import { SplitAuthorizationHeader } from "utils/misc"; -import { APITokenDocument, APIPermissions, UserAuthLevels } from "tachi-common"; import CreateLogCtx from "lib/logger/logger"; import { TachiConfig } from "lib/setup/config"; +import { APIPermissions, APITokenDocument, UserAuthLevels } from "tachi-common"; +import { SplitAuthorizationHeader } from "utils/misc"; const logger = CreateLogCtx(__filename); diff --git a/server/src/server/middleware/multer-upload.ts b/server/src/server/middleware/multer-upload.ts index 4b454dfab..d852394e5 100644 --- a/server/src/server/middleware/multer-upload.ts +++ b/server/src/server/middleware/multer-upload.ts @@ -1,10 +1,10 @@ // @todo #118 import { RequestHandler } from "express"; -import multer, { MulterError } from "multer"; -import CreateLogCtx from "lib/logger/logger"; -import { integer } from "tachi-common"; import { SIXTEEN_MEGABTYES } from "lib/constants/filesize"; +import CreateLogCtx from "lib/logger/logger"; +import multer, { MulterError } from "multer"; +import { integer } from "tachi-common"; const defaultLogger = CreateLogCtx(__filename); diff --git a/server/src/server/middleware/prudence-validate.test.ts b/server/src/server/middleware/prudence-validate.test.ts index 38c272df9..f7bec380b 100644 --- a/server/src/server/middleware/prudence-validate.test.ts +++ b/server/src/server/middleware/prudence-validate.test.ts @@ -1,7 +1,7 @@ -import t from "tap"; import expMiddlewareMock from "express-request-mock"; -import prValidate from "./prudence-validate"; import Prudence from "prudence"; +import t from "tap"; +import prValidate from "./prudence-validate"; t.test("#PrudenceMiddleware", (t) => { const mw = prValidate({ foo: Prudence.regex(/^baz$/u) }, { foo: "example error message" }); diff --git a/server/src/server/middleware/prudence-validate.ts b/server/src/server/middleware/prudence-validate.ts index e45f50f31..c65020a6d 100644 --- a/server/src/server/middleware/prudence-validate.ts +++ b/server/src/server/middleware/prudence-validate.ts @@ -1,11 +1,11 @@ -import Prudence, { - MiddlewareErrorHandler, - PrudenceSchema, - ErrorMessages, - PrudenceOptions, -} from "prudence"; import { RequestHandler } from "express-serve-static-core"; import CreateLogCtx from "lib/logger/logger"; +import Prudence, { + ErrorMessages, + MiddlewareErrorHandler, + PrudenceOptions, + PrudenceSchema, +} from "prudence"; const logger = CreateLogCtx(__filename); diff --git a/server/src/server/middleware/request-logger.ts b/server/src/server/middleware/request-logger.ts index 657bf4ea5..6bbb2c58a 100644 --- a/server/src/server/middleware/request-logger.ts +++ b/server/src/server/middleware/request-logger.ts @@ -1,6 +1,6 @@ -import CreateLogCtx from "lib/logger/logger"; import { RequestHandler, Response } from "express-serve-static-core"; import { SYMBOL_TachiAPIAuth } from "lib/constants/tachi"; +import CreateLogCtx from "lib/logger/logger"; import { TachiConfig } from "lib/setup/config"; const logger = CreateLogCtx(__filename); diff --git a/server/src/server/middleware/sanitise-qstring.test.ts b/server/src/server/middleware/sanitise-qstring.test.ts index bd8d4d3ae..efab76a62 100644 --- a/server/src/server/middleware/sanitise-qstring.test.ts +++ b/server/src/server/middleware/sanitise-qstring.test.ts @@ -1,6 +1,6 @@ -import SanitiseQString from "./sanitise-qstring"; -import t from "tap"; import expMiddlewareMock from "express-request-mock"; +import t from "tap"; +import SanitiseQString from "./sanitise-qstring"; t.test("#SanitiseQString", (t) => { t.test("Should allow GET requests with valid data.", async (t) => { diff --git a/server/src/server/router/api/v1/auth/auth.ts b/server/src/server/router/api/v1/auth/auth.ts index 9b89fff0e..57492b4ae 100644 --- a/server/src/server/router/api/v1/auth/auth.ts +++ b/server/src/server/router/api/v1/auth/auth.ts @@ -1,4 +1,7 @@ import bcrypt from "bcryptjs"; +import db from "external/mongo/db"; +import CreateLogCtx from "lib/logger/logger"; +import { Environment, ServerConfig } from "lib/setup/config"; import { integer, PrivateUserInfoDocument, @@ -6,13 +9,10 @@ import { UserAuthLevels, UserSettings, } from "tachi-common"; -import db from "external/mongo/db"; -import CreateLogCtx from "lib/logger/logger"; -import { FormatUserDoc } from "utils/user"; import nodeFetch from "utils/fetch"; import { Random20Hex } from "utils/misc"; -import { Environment, ServerConfig } from "lib/setup/config"; import { CreateURLWithParams } from "utils/url"; +import { FormatUserDoc } from "utils/user"; const logger = CreateLogCtx(__filename); diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/sessions/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/sessions/router.ts index 77a68fc9b..eeddf47b2 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/sessions/router.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/sessions/router.ts @@ -13,8 +13,7 @@ const router: Router = Router({ mergeParams: true }); * @name GET /api/v1/users/:userID/games/:game/:playtype/sessions */ router.get("/", async (req, res) => { - const { user, game, playtype } = GetUGPT(req); - + const { user, game, playtype } = GetUGPT(req); if (typeof req.query.search !== "string") { return res.status(400).json({ @@ -40,7 +39,7 @@ router.get("/", async (req, res) => { * @name GET /api/v1/users/:userID/games/:game/:playtype/sessions/best */ router.get("/best", async (req, res) => { - const { user, game, playtype } = GetUGPT(req); + const { user, game, playtype } = GetUGPT(req); const gptConfig = GetGamePTConfig(game, playtype); @@ -87,8 +86,7 @@ router.get("/best", async (req, res) => { * @name GET /api/v1/users/:userID/games/:game/:playtype/sessions/highlighted */ router.get("/highlighted", async (req, res) => { - const { user, game, playtype } = GetUGPT(req); - + const { user, game, playtype } = GetUGPT(req); const sessions = await db.sessions.find( { userID: user.id, game, playtype, highlight: true }, @@ -108,8 +106,7 @@ router.get("/highlighted", async (req, res) => { * @name GET /api/v1/users/:userID/games/:game/:playtype/sessions/recent */ router.get("/recent", async (req, res) => { - const { user, game, playtype } = GetUGPT(req); - + const { user, game, playtype } = GetUGPT(req); const sessions = await db.sessions.find( { userID: user.id, game, playtype }, @@ -129,8 +126,7 @@ router.get("/recent", async (req, res) => { * @name GET /api/v1/users/:userID/games/:game/:playtype/sessions/last */ router.get("/last", async (req, res) => { - const { user, game, playtype } = GetUGPT(req); - + const { user, game, playtype } = GetUGPT(req); const session = await db.sessions.findOne( { userID: user.id, game, playtype }, diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/settings/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/settings/router.ts index 1800e532c..aec8c30f7 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/settings/router.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/settings/router.ts @@ -1,6 +1,5 @@ import { Router } from "express"; import db from "external/mongo/db"; -import { SYMBOL_TachiData } from "lib/constants/tachi"; import CreateLogCtx from "lib/logger/logger"; import p from "prudence"; import { RequirePermissions } from "server/middleware/auth"; diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/router.ts index 842e2aa9b..120f71b34 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/router.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/router.ts @@ -1,6 +1,5 @@ import { Router } from "express"; import db from "external/mongo/db"; -import { SYMBOL_TachiData } from "lib/constants/tachi"; import { GetUGPT } from "utils/req-tachi-data"; import goalsRouter from "./goals/router"; import milestonesRouter from "./milestones/router"; @@ -133,5 +132,6 @@ router.get("/recently-interacted", async (req, res) => { }); router.use("/goals", goalsRouter); +router.use("/milestones", milestonesRouter); export default router; diff --git a/server/src/server/router/ir/router.ts b/server/src/server/router/ir/router.ts index 5dd7ce82c..3a58cd1e1 100644 --- a/server/src/server/router/ir/router.ts +++ b/server/src/server/router/ir/router.ts @@ -11,8 +11,8 @@ import beatorajaIR from "./beatoraja/router"; import directManualIR from "./direct-manual/router"; import fervidexIR from "./fervidex/router"; import ksHookIR from "./kshook/router"; -import uscIR from "./usc/router"; import lr2hookIR from "./lr2hook/router"; +import uscIR from "./usc/router"; const router: Router = Router({ mergeParams: true }); diff --git a/server/src/test-utils/mock-api.ts b/server/src/test-utils/mock-api.ts index a30f23fab..c24e4f62f 100644 --- a/server/src/test-utils/mock-api.ts +++ b/server/src/test-utils/mock-api.ts @@ -1,10 +1,9 @@ -import supertest from "supertest"; import CreateLogCtx from "lib/logger/logger"; +import supertest from "supertest"; +import server from "../server/server"; const logger = CreateLogCtx(__filename); -import server from "../server/server"; - logger.verbose("Creating Mock Server Connection..."); const connection = server.listen(); diff --git a/server/src/test-utils/server.ts b/server/src/test-utils/server.ts index f8806cf6f..2ec386f46 100644 --- a/server/src/test-utils/server.ts +++ b/server/src/test-utils/server.ts @@ -1,5 +1,5 @@ -import server from "../server/server"; import supertest from "supertest"; +import server from "../server/server"; const mockServer = supertest(server);