fix: handle saveDialogue without YearIteration having been supplied #1774

Merged
Sainan merged 1 commits from hex-fix into main 2025-04-22 09:59:55 -07:00
3 changed files with 6 additions and 11 deletions

View File

@ -12,22 +12,17 @@ export const saveDialogueController: RequestHandler = async (req, res) => {
const request = JSON.parse(String(req.body)) as SaveDialogueRequest; const request = JSON.parse(String(req.body)) as SaveDialogueRequest;
if ("YearIteration" in request) { if ("YearIteration" in request) {
const inventory = await getInventory(accountId, "DialogueHistory"); const inventory = await getInventory(accountId, "DialogueHistory");
if (inventory.DialogueHistory) { inventory.DialogueHistory ??= {};
inventory.DialogueHistory.YearIteration = request.YearIteration; inventory.DialogueHistory.YearIteration = request.YearIteration;
} else {
inventory.DialogueHistory = { YearIteration: request.YearIteration };
}
await inventory.save(); await inventory.save();
res.end(); res.end();
} else { } else {
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
if (!inventory.DialogueHistory) {
throw new Error("bad inventory state");
}
const inventoryChanges: IInventoryChanges = {}; const inventoryChanges: IInventoryChanges = {};
const tomorrowAt0Utc = config.noKimCooldowns const tomorrowAt0Utc = config.noKimCooldowns
? Date.now() ? Date.now()
: (Math.trunc(Date.now() / 86400_000) + 1) * 86400_000; : (Math.trunc(Date.now() / 86400_000) + 1) * 86400_000;
inventory.DialogueHistory ??= {};
inventory.DialogueHistory.Dialogues ??= []; inventory.DialogueHistory.Dialogues ??= [];
const dialogue = getDialogue(inventory, request.DialogueName); const dialogue = getDialogue(inventory, request.DialogueName);
dialogue.Rank = request.Rank; dialogue.Rank = request.Rank;

View File

@ -909,7 +909,7 @@ dialogueSchema.set("toJSON", {
const dialogueHistorySchema = new Schema<IDialogueHistoryDatabase>( const dialogueHistorySchema = new Schema<IDialogueHistoryDatabase>(
{ {
YearIteration: { type: Number, required: true }, YearIteration: Number,
Resets: Number, Resets: Number,
Dialogues: { type: [dialogueSchema], required: false } Dialogues: { type: [dialogueSchema], required: false }
}, },

View File

@ -1130,13 +1130,13 @@ export interface IEndlessXpProgress {
} }
export interface IDialogueHistoryClient { export interface IDialogueHistoryClient {
YearIteration: number; YearIteration?: number;
Resets?: number; // added in 38.5.0 Resets?: number; // added in 38.5.0
Dialogues?: IDialogueClient[]; Dialogues?: IDialogueClient[];
} }
export interface IDialogueHistoryDatabase { export interface IDialogueHistoryDatabase {
YearIteration: number; YearIteration?: number;
Resets?: number; Resets?: number;
Dialogues?: IDialogueDatabase[]; Dialogues?: IDialogueDatabase[];
} }