chore: use inventory projection for updateChallengeProgress

This commit is contained in:
Sainan 2025-03-24 09:56:21 +01:00
parent 0085c20e11
commit 21e42284c3
2 changed files with 7 additions and 18 deletions

View File

@ -1,16 +1,17 @@
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getAccountIdForRequest } from "@/src/services/loginService"; import { getAccountIdForRequest } from "@/src/services/loginService";
import { updateChallengeProgress } from "@/src/services/inventoryService";
import { IUpdateChallengeProgressRequest } from "@/src/types/requestTypes"; import { IUpdateChallengeProgressRequest } from "@/src/types/requestTypes";
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
const updateChallengeProgressController: RequestHandler = async (req, res) => { export const updateChallengeProgressController: RequestHandler = async (req, res) => {
const payload = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body)); const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
const accountId = await getAccountIdForRequest(req); 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(); res.status(200).end();
}; };
export { updateChallengeProgressController };

View File

@ -1205,18 +1205,6 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus
inventory.FocusXP.AP_WARD += focusXpPlus[FocusType.AP_WARD]; inventory.FocusXP.AP_WARD += focusXpPlus[FocusType.AP_WARD];
}; };
export const updateChallengeProgress = async (
challenges: IUpdateChallengeProgressRequest,
accountId: string
): Promise<void> => {
const inventory = await getInventory(accountId);
addChallenges(inventory, challenges.ChallengeProgress);
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
await inventory.save();
};
export const addSeasonalChallengeHistory = ( export const addSeasonalChallengeHistory = (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,
itemsArray: ISeasonChallenge[] | undefined itemsArray: ISeasonChallenge[] | undefined