fix: move getDialogue preconditions into the function itself #2679

Merged
Sainan merged 1 commits from getDialogue-precond into main 2025-08-22 11:46:06 -07:00
2 changed files with 5 additions and 5 deletions

View File

@ -20,8 +20,6 @@ export const saveDialogueController: RequestHandler = async (req, res) => {
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 ??= [];
const dialogue = getDialogue(inventory, request.DialogueName); const dialogue = getDialogue(inventory, request.DialogueName);
dialogue.Rank = request.Rank; dialogue.Rank = request.Rank;
dialogue.Chemistry += request.Chemistry; dialogue.Chemistry += request.Chemistry;

View File

@ -2286,11 +2286,13 @@ export const cleanupInventory = (inventory: TInventoryDatabaseDocument): void =>
}; };
export const getDialogue = (inventory: TInventoryDatabaseDocument, dialogueName: string): IDialogueDatabase => { export const getDialogue = (inventory: TInventoryDatabaseDocument, dialogueName: string): IDialogueDatabase => {
let dialogue = inventory.DialogueHistory!.Dialogues!.find(x => x.DialogueName == dialogueName); inventory.DialogueHistory ??= {};
inventory.DialogueHistory.Dialogues ??= [];
let dialogue = inventory.DialogueHistory.Dialogues.find(x => x.DialogueName == dialogueName);
if (!dialogue) { if (!dialogue) {
dialogue = dialogue =
inventory.DialogueHistory!.Dialogues![ inventory.DialogueHistory.Dialogues[
inventory.DialogueHistory!.Dialogues!.push({ inventory.DialogueHistory.Dialogues.push({
Rank: 0, Rank: 0,
Chemistry: 0, Chemistry: 0,
AvailableDate: new Date(0), AvailableDate: new Date(0),