From 3b20a109f65fa7f9763f1abcd463ca0ff094457f Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Tue, 22 Apr 2025 09:59:54 -0700 Subject: [PATCH] fix: handle saveDialogue without YearIteration having been supplied (#1774) This is needed for The Hex rank up dialogues, which are independent of the year iterations. Fixes #1773 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1774 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- src/controllers/api/saveDialogueController.ts | 11 +++-------- src/models/inventoryModels/inventoryModel.ts | 2 +- src/types/inventoryTypes/inventoryTypes.ts | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/controllers/api/saveDialogueController.ts b/src/controllers/api/saveDialogueController.ts index 7d7d6380..49cc605c 100644 --- a/src/controllers/api/saveDialogueController.ts +++ b/src/controllers/api/saveDialogueController.ts @@ -12,22 +12,17 @@ export const saveDialogueController: RequestHandler = async (req, res) => { const request = JSON.parse(String(req.body)) as SaveDialogueRequest; if ("YearIteration" in request) { const inventory = await getInventory(accountId, "DialogueHistory"); - if (inventory.DialogueHistory) { - inventory.DialogueHistory.YearIteration = request.YearIteration; - } else { - inventory.DialogueHistory = { YearIteration: request.YearIteration }; - } + inventory.DialogueHistory ??= {}; + inventory.DialogueHistory.YearIteration = request.YearIteration; await inventory.save(); res.end(); } else { const inventory = await getInventory(accountId); - if (!inventory.DialogueHistory) { - throw new Error("bad inventory state"); - } const inventoryChanges: IInventoryChanges = {}; const tomorrowAt0Utc = config.noKimCooldowns ? Date.now() : (Math.trunc(Date.now() / 86400_000) + 1) * 86400_000; + inventory.DialogueHistory ??= {}; inventory.DialogueHistory.Dialogues ??= []; const dialogue = getDialogue(inventory, request.DialogueName); dialogue.Rank = request.Rank; diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 775de04a..6b73186f 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -909,7 +909,7 @@ dialogueSchema.set("toJSON", { const dialogueHistorySchema = new Schema( { - YearIteration: { type: Number, required: true }, + YearIteration: Number, Resets: Number, Dialogues: { type: [dialogueSchema], required: false } }, diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index 219f43a5..8ddfbf42 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -1130,13 +1130,13 @@ export interface IEndlessXpProgress { } export interface IDialogueHistoryClient { - YearIteration: number; + YearIteration?: number; Resets?: number; // added in 38.5.0 Dialogues?: IDialogueClient[]; } export interface IDialogueHistoryDatabase { - YearIteration: number; + YearIteration?: number; Resets?: number; Dialogues?: IDialogueDatabase[]; }