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 11:32:01 -07:00
|
|
|
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
|
2025-03-24 21:52:03 +01:00
|
|
|
import { ExportNightwave } from "warframe-public-export-plus";
|
|
|
|
import { logger } from "@/src/utils/logger";
|
|
|
|
import { IAffiliationMods } from "@/src/types/purchaseTypes";
|
2024-05-28 13:52:27 +02:00
|
|
|
|
2025-03-24 11:32:01 -07: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 21:52:03 +01:00
|
|
|
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
|
|
|
|
if (challenges.ChallengeProgress) {
|
|
|
|
addChallenges(inventory, challenges.ChallengeProgress);
|
|
|
|
}
|
|
|
|
if (challenges.SeasonChallengeHistory) {
|
|
|
|
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
|
|
|
|
}
|
|
|
|
const affiliationMods: IAffiliationMods[] = [];
|
|
|
|
if (challenges.ChallengeProgress && challenges.SeasonChallengeCompletions) {
|
|
|
|
for (const challenge of challenges.SeasonChallengeCompletions) {
|
|
|
|
// Ignore challenges that weren't completed just now
|
|
|
|
if (!challenges.ChallengeProgress.find(x => challenge.challenge.indexOf(x.Name) != -1)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const meta = ExportNightwave.challenges[challenge.challenge];
|
|
|
|
logger.debug("Completed challenge", meta);
|
|
|
|
|
|
|
|
let affiliation = inventory.Affiliations.find(x => x.Tag == ExportNightwave.affiliationTag);
|
|
|
|
if (!affiliation) {
|
|
|
|
affiliation =
|
|
|
|
inventory.Affiliations[
|
|
|
|
inventory.Affiliations.push({
|
|
|
|
Tag: ExportNightwave.affiliationTag,
|
|
|
|
Standing: 0
|
|
|
|
}) - 1
|
|
|
|
];
|
|
|
|
}
|
|
|
|
affiliation.Standing += meta.standing;
|
|
|
|
|
|
|
|
if (affiliationMods.length == 0) {
|
|
|
|
affiliationMods.push({ Tag: ExportNightwave.affiliationTag });
|
|
|
|
}
|
|
|
|
affiliationMods[0].Standing ??= 0;
|
|
|
|
affiliationMods[0].Standing += meta.standing;
|
|
|
|
}
|
|
|
|
}
|
2025-03-24 11:32:01 -07:00
|
|
|
await inventory.save();
|
2024-06-02 18:35:06 +03:00
|
|
|
|
2025-03-24 21:52:03 +01:00
|
|
|
res.json({
|
|
|
|
AffiliationMods: affiliationMods
|
|
|
|
});
|
2023-05-19 15:22:48 -03:00
|
|
|
};
|
|
|
|
|
2025-03-24 11:32:01 -07:00
|
|
|
interface IUpdateChallengeProgressRequest {
|
2025-03-24 21:52:03 +01:00
|
|
|
ChallengeProgress?: IChallengeProgress[];
|
|
|
|
SeasonChallengeHistory?: ISeasonChallenge[];
|
|
|
|
SeasonChallengeCompletions?: ISeasonChallenge[];
|
2025-03-24 11:32:01 -07:00
|
|
|
}
|