2023-05-19 15:22:48 -03:00
|
|
|
import { RequestHandler } from "express";
|
2024-05-28 13:52:27 +02:00
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-03-24 09:56:21 +01:00
|
|
|
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
|
2025-03-24 09:58:38 +01:00
|
|
|
import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
|
2024-05-28 13:52:27 +02:00
|
|
|
|
2025-03-24 09:56:21 +01:00
|
|
|
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
|
|
|
|
const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
|
2024-05-28 13:52:27 +02:00
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2024-06-02 18:35:06 +03:00
|
|
|
|
2025-03-24 09:56:21 +01:00
|
|
|
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory");
|
|
|
|
addChallenges(inventory, challenges.ChallengeProgress);
|
|
|
|
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
|
|
|
|
await inventory.save();
|
2024-06-02 18:35:06 +03:00
|
|
|
|
2024-05-28 13:52:27 +02:00
|
|
|
res.status(200).end();
|
2023-05-19 15:22:48 -03:00
|
|
|
};
|
2025-03-24 09:58:38 +01:00
|
|
|
|
|
|
|
interface IUpdateChallengeProgressRequest {
|
|
|
|
ChallengeProgress: IChallengeProgress[];
|
|
|
|
SeasonChallengeHistory: ISeasonChallenge[];
|
|
|
|
SeasonChallengeCompletions: ISeasonChallenge[];
|
|
|
|
}
|