diff --git a/src/services/questService.ts b/src/services/questService.ts index e53126c5..ae7c8133 100644 --- a/src/services/questService.ts +++ b/src/services/questService.ts @@ -3,6 +3,7 @@ import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/invento import { IInventoryDatabase, IQuestKeyDatabase, IQuestStage } from "@/src/types/inventoryTypes/inventoryTypes"; import { logger } from "@/src/utils/logger"; import { HydratedDocument } from "mongoose"; +import { config } from "@/src/services/configService"; export interface IUpdateQuestRequest { QuestKeys: Omit[]; @@ -22,10 +23,10 @@ export const updateQuestKey = ( throw new Error("more than 1 quest key not supported"); } - const questKeyIndex = inventory.QuestKeys.findIndex(questKey => questKey.ItemType === questKeyUpdate[0].ItemType); - + let questKeyIndex = inventory.QuestKeys.findIndex(questKey => questKey.ItemType === questKeyUpdate[0].ItemType); if (questKeyIndex === -1) { - throw new Error(`quest key ${questKeyUpdate[0].ItemType} not found`); + if (!config.unlockAllQuests) throw new Error(`quest key ${questKeyUpdate[0].ItemType} not found`); + questKeyIndex = inventory.QuestKeys.push({ ItemType: questKeyUpdate[0].ItemType }) - 1; } inventory.QuestKeys[questKeyIndex] = questKeyUpdate[0];