From 35ec22e3c0a67c1bcd972bab1e360bf50ee0f80c Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Tue, 29 Mar 2022 15:17:45 +0100 Subject: [PATCH] Rename the types, too --- server/src/external/mongo/db.ts | 8 ++++---- .../score-import/framework/goals/goals.test.ts | 18 +++++++++--------- .../lib/score-import/framework/goals/goals.ts | 10 +++++----- .../framework/milestones/milestones.ts | 4 ++-- server/src/lib/targets/goals.ts | 4 ++-- .../games/_game/_playtype/router.test.ts | 8 ++++---- .../_userID/games/_game/_playtype/router.ts | 8 ++++---- .../_playtype/targets/milestones/router.ts | 4 ++-- server/src/test-utils/test-data.ts | 4 ++-- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/server/src/external/mongo/db.ts b/server/src/external/mongo/db.ts index d27660026..527db645f 100644 --- a/server/src/external/mongo/db.ts +++ b/server/src/external/mongo/db.ts @@ -36,8 +36,8 @@ import { UGPTSettings, UserGameStats, UserGameStatsSnapshot, - UserGoalDocument, - UserMilestoneDocument, + GoalSubscriptionDocument, + MilestoneSubscriptionDocument, UserSettings, } from "tachi-common"; import { GetMillisecondsSince } from "utils/misc"; @@ -152,9 +152,9 @@ const db = { folders: monkDB.get("folders"), "folder-chart-lookup": monkDB.get("folder-chart-lookup"), goals: monkDB.get("goals"), - "goal-subs": monkDB.get("goal-subs"), + "goal-subs": monkDB.get("goal-subs"), milestones: monkDB.get("milestones"), - "milestone-subs": monkDB.get("milestone-subs"), + "milestone-subs": monkDB.get("milestone-subs"), users: monkDB.get("users"), imports: monkDB.get("imports"), "import-timings": monkDB.get("import-timings"), diff --git a/server/src/lib/score-import/framework/goals/goals.test.ts b/server/src/lib/score-import/framework/goals/goals.test.ts index 10b9f0ec1..3c421a980 100644 --- a/server/src/lib/score-import/framework/goals/goals.test.ts +++ b/server/src/lib/score-import/framework/goals/goals.test.ts @@ -2,7 +2,7 @@ import t from "tap"; import db from "external/mongo/db"; import ResetDBState from "test-utils/resets"; import { GetRelevantFolderGoals, GetRelevantGoals, UpdateGoalsForUser, ProcessGoal } from "./goals"; -import { GoalDocument, UserGoalDocument } from "tachi-common"; +import { GoalDocument, GoalSubscriptionDocument } from "tachi-common"; import { CreateFolderChartLookup } from "utils/folder"; import { GetKTDataJSON, @@ -182,7 +182,7 @@ t.test("#UpdateGoalsForUser", (t) => { }, }; - const baseUserGoalDocument: UserGoalDocument = { + const baseGoalSubscriptionDocument: GoalSubscriptionDocument = { achieved: false, wasInstantlyAchieved: false, game: "iidx", @@ -205,14 +205,14 @@ t.test("#UpdateGoalsForUser", (t) => { await db.goals.insert(baseGoalDocument); delete baseGoalDocument._id; - await db["goal-subs"].insert(baseUserGoalDocument); + await db["goal-subs"].insert(baseGoalSubscriptionDocument); // we dont delete _id here because updategoalsforuser // depends on usergoal _id await db["personal-bests"].insert(TestingIIDXSPScorePB); delete TestingIIDXSPScorePB._id; - const ugMap = new Map([["FAKE_GOAL_ID", baseUserGoalDocument]]); + const ugMap = new Map([["FAKE_GOAL_ID", baseGoalSubscriptionDocument]]); const res = await UpdateGoalsForUser([baseGoalDocument], ugMap, 1, logger); @@ -250,7 +250,7 @@ t.test("#UpdateGoalsForUser", (t) => { "Should update goals in the database." ); - delete baseUserGoalDocument._id; + delete baseGoalSubscriptionDocument._id; t.end(); }); @@ -259,10 +259,10 @@ t.test("#UpdateGoalsForUser", (t) => { const goal = deepmerge(baseGoalDocument, { criteria: { value: 2 } }); await db.goals.insert(goal); - const goalSub = deepmerge(baseUserGoalDocument, { + const goalSub = deepmerge(baseGoalSubscriptionDocument, { outOf: 2, outOfHuman: "2", - }) as unknown as UserGoalDocument; + }) as unknown as GoalSubscriptionDocument; await db["goal-subs"].insert(goalSub); // we dont delete _id here because updategoalsforuser @@ -310,7 +310,7 @@ t.test("#UpdateGoalsForUser", (t) => { "Should update goals in the database." ); - delete baseUserGoalDocument._id; + delete baseGoalSubscriptionDocument._id; t.end(); }); @@ -334,7 +334,7 @@ t.test("#UpdateGoalsForUser", (t) => { t.test("Should handle (skip) invalid goals.", async (t) => { const res = await UpdateGoalsForUser( [deepmerge(baseGoalDocument, { charts: { type: "INVALID" } })], - new Map([["FAKE_GOAL_ID", baseUserGoalDocument]]), + new Map([["FAKE_GOAL_ID", baseGoalSubscriptionDocument]]), 1, logger ); diff --git a/server/src/lib/score-import/framework/goals/goals.ts b/server/src/lib/score-import/framework/goals/goals.ts index d51d93bc4..b47e0105c 100644 --- a/server/src/lib/score-import/framework/goals/goals.ts +++ b/server/src/lib/score-import/framework/goals/goals.ts @@ -1,4 +1,4 @@ -import { integer, Game, GoalDocument, UserGoalDocument } from "tachi-common"; +import { integer, Game, GoalDocument, GoalSubscriptionDocument } from "tachi-common"; import { EvaluateGoalForUser } from "lib/targets/goals"; import db from "external/mongo/db"; import { KtLogger } from "lib/logger/logger"; @@ -27,7 +27,7 @@ export async function GetAndUpdateUsersGoals( export async function UpdateGoalsForUser( goals: GoalDocument[], - goalSubsMap: Map, + goalSubsMap: Map, userID: integer, logger: KtLogger ) { @@ -89,7 +89,7 @@ export async function UpdateGoalsForUser( */ export async function ProcessGoal( goal: GoalDocument, - goalSub: UserGoalDocument, + goalSub: GoalSubscriptionDocument, userID: integer, logger: KtLogger ) { @@ -172,7 +172,7 @@ export async function GetRelevantGoals( userID: integer, chartIDs: Set, logger: KtLogger -): Promise<{ goals: GoalDocument[]; goalSubsMap: Map }> { +): Promise<{ goals: GoalDocument[]; goalSubsMap: Map }> { const goalSubs = await db["goal-subs"].find({ game, userID }, { projectID: true }); logger.verbose(`Found user has ${goalSubs.length} goals.`); @@ -204,7 +204,7 @@ export async function GetRelevantGoals( const goalSet = new Set(goals.map((e) => e.goalID)); - const goalSubsMap: Map = new Map(); + const goalSubsMap: Map = new Map(); for (const goalSub of goalSubs) { if (!goalSet.has(goalSub.goalID)) { diff --git a/server/src/lib/score-import/framework/milestones/milestones.ts b/server/src/lib/score-import/framework/milestones/milestones.ts index 357276661..9f6518922 100644 --- a/server/src/lib/score-import/framework/milestones/milestones.ts +++ b/server/src/lib/score-import/framework/milestones/milestones.ts @@ -9,7 +9,7 @@ import { MilestoneDocument, MilestoneImportInfo, Playtypes, - UserMilestoneDocument, + MilestoneSubscriptionDocument, } from "tachi-common"; import { CalculateMilestoneOutOf, GetGoalIDsFromMilestone } from "utils/milestone"; @@ -85,7 +85,7 @@ export async function UpdateUsersMilestones( importGoalMap.set(ig.goalID, ig.new); } - const bwrite: BulkWriteUpdateOneOperation[] = []; + const bwrite: BulkWriteUpdateOneOperation[] = []; const importMilestoneInfo: MilestoneImportInfo[] = []; diff --git a/server/src/lib/targets/goals.ts b/server/src/lib/targets/goals.ts index b48399cd6..0f4ba6673 100644 --- a/server/src/lib/targets/goals.ts +++ b/server/src/lib/targets/goals.ts @@ -10,7 +10,7 @@ import { integer, PBScoreDocument, Playtypes, - UserGoalDocument, + GoalSubscriptionDocument, } from "tachi-common"; import { GetFolderChartIDs } from "utils/folder"; import { CreateGoalTitle, ValidateGoalChartsAndCriteria } from "./goal-utils"; @@ -319,7 +319,7 @@ export async function SubscribeToGoal( // @ts-expect-error TS can't resolve this. // because it can't explode out the types. - const goalSub: UserGoalDocument = { + const goalSub: GoalSubscriptionDocument = { outOf: result.outOf, outOfHuman: result.outOfHuman, progress: result.progress, 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 index ca59ca6f8..aff060fba 100644 --- 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 @@ -4,8 +4,8 @@ import { GoalDocument, MilestoneDocument, ScoreDocument, - UserGoalDocument, - UserMilestoneDocument, + GoalSubscriptionDocument, + MilestoneSubscriptionDocument, } from "tachi-common"; import t from "tap"; import mockApi from "test-utils/mock-api"; @@ -201,7 +201,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/goals", (t) => { playtype: "SP", achieved: true, }, - ] as UserGoalDocument[]); + ] as GoalSubscriptionDocument[]); await db.goals.insert([{ goalID: "foo" }, { goalID: "bar" }] as GoalDocument[]); @@ -271,7 +271,7 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/milestones", (t) => { playtype: "SP", achieved: true, }, - ] as UserMilestoneDocument[]); + ] as MilestoneSubscriptionDocument[]); await db.milestones.insert([ { milestoneID: "foo" }, 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 f8bbdcfbe..f0cc5e709 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 @@ -7,8 +7,8 @@ import { integer, PBScoreDocument, UserGameStatsSnapshot, - UserGoalDocument, - UserMilestoneDocument, + GoalSubscriptionDocument, + MilestoneSubscriptionDocument, } from "tachi-common"; import { IsString } from "utils/misc"; import { CheckStrProfileAlg } from "utils/string-checks"; @@ -146,7 +146,7 @@ router.get("/goals", async (req, res) => { const game = req[SYMBOL_TachiData]!.game!; const playtype = req[SYMBOL_TachiData]!.playtype!; - const query: FilterQuery = { + const query: FilterQuery = { userID: user.id, game, playtype, @@ -183,7 +183,7 @@ router.get("/milestones", async (req, res) => { const game = req[SYMBOL_TachiData]!.game!; const playtype = req[SYMBOL_TachiData]!.playtype!; - const query: FilterQuery = { + const query: FilterQuery = { userID: user.id, game, playtype, diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/milestones/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/milestones/router.ts index 09e3bad3a..cd1787f0c 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/milestones/router.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/milestones/router.ts @@ -7,7 +7,7 @@ import { GetGoalsInMilestone, } from "lib/targets/milestones"; import { RequirePermissions } from "server/middleware/auth"; -import { UserMilestoneDocument } from "tachi-common"; +import { MilestoneSubscriptionDocument } from "tachi-common"; import { GetMilestoneForIDGuaranteed } from "utils/db"; import { AssignToReqTachiData } from "utils/req-tachi-data"; import { FormatUserDoc } from "utils/user"; @@ -152,7 +152,7 @@ router.put("/:milestoneID", RequirePermissions(""), async (req, res) => { }); } - const milestoneSub: UserMilestoneDocument = { + const milestoneSub: MilestoneSubscriptionDocument = { achieved, game, }; diff --git a/server/src/test-utils/test-data.ts b/server/src/test-utils/test-data.ts index ac54ad1ec..f9a22bca5 100644 --- a/server/src/test-utils/test-data.ts +++ b/server/src/test-utils/test-data.ts @@ -21,7 +21,7 @@ import { PBScoreDocument, ScoreDocument, SongDocument, - UserGoalDocument, + GoalSubscriptionDocument, } from "tachi-common"; import { ApplyNTimes, RFA } from "utils/misc"; @@ -422,7 +422,7 @@ export const HC511Goal: GoalDocument = { }, }; -export const HC511UserGoal: UserGoalDocument = { +export const HC511UserGoal: GoalSubscriptionDocument = { achieved: false, wasInstantlyAchieved: false, timeAchieved: null,