SpaceNinjaServer/src/controllers/api/updateChallengeProgressController.ts
Sainan 7d9e235a6e
All checks were successful
Build / build (22) (push) Successful in 41s
Build / build (20) (push) Successful in 1m11s
Build / build (18) (push) Successful in 1m17s
Build / build (18) (pull_request) Successful in 43s
Build / build (20) (pull_request) Successful in 1m12s
Build / build (22) (pull_request) Successful in 1m16s
move request type
2025-03-24 09:58:38 +01:00

24 lines
1.1 KiB
TypeScript

import { RequestHandler } from "express";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
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();
};
interface IUpdateChallengeProgressRequest {
ChallengeProgress: IChallengeProgress[];
SeasonChallengeHistory: ISeasonChallenge[];
SeasonChallengeCompletions: ISeasonChallenge[];
}