SpaceNinjaServer/src/controllers/api/updateChallengeProgressController.ts

24 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-05-19 15:22:48 -03:00
import { RequestHandler } from "express";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
2025-03-24 09:58:38 +01:00
import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory");
addChallenges(inventory, challenges.ChallengeProgress);
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
await inventory.save();
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[];
}