Rename the types, too

This commit is contained in:
zkldi
2022-03-29 15:17:45 +01:00
parent 5860f4e499
commit 35ec22e3c0
9 changed files with 34 additions and 34 deletions
+4 -4
View File
@@ -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<FolderDocument>("folders"),
"folder-chart-lookup": monkDB.get<FolderChartLookup>("folder-chart-lookup"),
goals: monkDB.get<GoalDocument>("goals"),
"goal-subs": monkDB.get<UserGoalDocument>("goal-subs"),
"goal-subs": monkDB.get<GoalSubscriptionDocument>("goal-subs"),
milestones: monkDB.get<MilestoneDocument>("milestones"),
"milestone-subs": monkDB.get<UserMilestoneDocument>("milestone-subs"),
"milestone-subs": monkDB.get<MilestoneSubscriptionDocument>("milestone-subs"),
users: monkDB.get<PublicUserDocument>("users"),
imports: monkDB.get<ImportDocument>("imports"),
"import-timings": monkDB.get<ImportTimingsDocument>("import-timings"),
@@ -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
);
@@ -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<string, UserGoalDocument>,
goalSubsMap: Map<string, GoalSubscriptionDocument>,
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<string>,
logger: KtLogger
): Promise<{ goals: GoalDocument[]; goalSubsMap: Map<string, UserGoalDocument> }> {
): Promise<{ goals: GoalDocument[]; goalSubsMap: Map<string, GoalSubscriptionDocument> }> {
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<string, UserGoalDocument> = new Map();
const goalSubsMap: Map<string, GoalSubscriptionDocument> = new Map();
for (const goalSub of goalSubs) {
if (!goalSet.has(goalSub.goalID)) {
@@ -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<UserMilestoneDocument>[] = [];
const bwrite: BulkWriteUpdateOneOperation<MilestoneSubscriptionDocument>[] = [];
const importMilestoneInfo: MilestoneImportInfo[] = [];
+2 -2
View File
@@ -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,
@@ -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" },
@@ -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<UserGoalDocument> = {
const query: FilterQuery<GoalSubscriptionDocument> = {
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<UserMilestoneDocument> = {
const query: FilterQuery<MilestoneSubscriptionDocument> = {
userID: user.id,
game,
playtype,
@@ -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,
};
+2 -2
View File
@@ -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,