diff --git a/src/controllers/api/updateChallengeProgressController.ts b/src/controllers/api/updateChallengeProgressController.ts index 2889a333..dabeff84 100644 --- a/src/controllers/api/updateChallengeProgressController.ts +++ b/src/controllers/api/updateChallengeProgressController.ts @@ -1,16 +1,17 @@ import { RequestHandler } from "express"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { getAccountIdForRequest } from "@/src/services/loginService"; -import { updateChallengeProgress } from "@/src/services/inventoryService"; import { IUpdateChallengeProgressRequest } from "@/src/types/requestTypes"; +import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService"; -const updateChallengeProgressController: RequestHandler = async (req, res) => { - const payload = getJSONfromString(String(req.body)); +export const updateChallengeProgressController: RequestHandler = async (req, res) => { + const challenges = getJSONfromString(String(req.body)); const accountId = await getAccountIdForRequest(req); - await updateChallengeProgress(payload, accountId); + const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory"); + addChallenges(inventory, challenges.ChallengeProgress); + addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory); + await inventory.save(); res.status(200).end(); }; - -export { updateChallengeProgressController }; diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index b90d97df..461ea7df 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -1205,18 +1205,6 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus inventory.FocusXP.AP_WARD += focusXpPlus[FocusType.AP_WARD]; }; -export const updateChallengeProgress = async ( - challenges: IUpdateChallengeProgressRequest, - accountId: string -): Promise => { - const inventory = await getInventory(accountId); - - addChallenges(inventory, challenges.ChallengeProgress); - addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory); - - await inventory.save(); -}; - export const addSeasonalChallengeHistory = ( inventory: TInventoryDatabaseDocument, itemsArray: ISeasonChallenge[] | undefined