forked from OpenWF/SpaceNinjaServer
		
	chore: use inventory projection for updateChallengeProgress
This commit is contained in:
		
							parent
							
								
									0085c20e11
								
							
						
					
					
						commit
						21e42284c3
					
				@ -1,16 +1,17 @@
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { updateChallengeProgress } from "@/src/services/inventoryService";
 | 
			
		||||
import { IUpdateChallengeProgressRequest } from "@/src/types/requestTypes";
 | 
			
		||||
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
 | 
			
		||||
const updateChallengeProgressController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const payload = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
 | 
			
		||||
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
 | 
			
		||||
    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();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export { updateChallengeProgressController };
 | 
			
		||||
 | 
			
		||||
@ -1205,18 +1205,6 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus
 | 
			
		||||
    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 = (
 | 
			
		||||
    inventory: TInventoryDatabaseDocument,
 | 
			
		||||
    itemsArray: ISeasonChallenge[] | undefined
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user