fix: move getDialogue preconditions into the function itself (#2679)
Closes #2678 Reviewed-on: #2679 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									9c232bfc1f
								
							
						
					
					
						commit
						5e1ff64cca
					
				@ -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;
 | 
				
			||||||
 | 
				
			|||||||
@ -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),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user