forked from OpenWF/SpaceNinjaServer
		
	chore: report unknown fields in updateChallengeProgress payload (#2210)
Reviewed-on: OpenWF/SpaceNinjaServer#2210 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									88d4ba6340
								
							
						
					
					
						commit
						e686a2d028
					
				@ -4,6 +4,8 @@ import { getAccountForRequest } from "@/src/services/loginService";
 | 
				
			|||||||
import { addChallenges, getInventory } from "@/src/services/inventoryService";
 | 
					import { addChallenges, getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IAffiliationMods } from "@/src/types/purchaseTypes";
 | 
					import { IAffiliationMods } from "@/src/types/purchaseTypes";
 | 
				
			||||||
 | 
					import { getEntriesUnsafe } from "@/src/utils/ts-utils";
 | 
				
			||||||
 | 
					import { logger } from "@/src/utils/logger";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
 | 
					export const updateChallengeProgressController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
 | 
					    const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
 | 
				
			||||||
@ -13,9 +15,6 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
 | 
				
			|||||||
        account._id.toString(),
 | 
					        account._id.toString(),
 | 
				
			||||||
        "ChallengesFixVersion ChallengeProgress SeasonChallengeHistory Affiliations"
 | 
					        "ChallengesFixVersion ChallengeProgress SeasonChallengeHistory Affiliations"
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    if (challenges.ChallengesFixVersion !== undefined) {
 | 
					 | 
				
			||||||
        inventory.ChallengesFixVersion = challenges.ChallengesFixVersion;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    let affiliationMods: IAffiliationMods[] = [];
 | 
					    let affiliationMods: IAffiliationMods[] = [];
 | 
				
			||||||
    if (challenges.ChallengeProgress) {
 | 
					    if (challenges.ChallengeProgress) {
 | 
				
			||||||
        affiliationMods = addChallenges(
 | 
					        affiliationMods = addChallenges(
 | 
				
			||||||
@ -25,8 +24,14 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
 | 
				
			|||||||
            challenges.SeasonChallengeCompletions
 | 
					            challenges.SeasonChallengeCompletions
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (challenges.SeasonChallengeHistory) {
 | 
					    for (const [key, value] of getEntriesUnsafe(challenges)) {
 | 
				
			||||||
        challenges.SeasonChallengeHistory.forEach(({ challenge, id }) => {
 | 
					        switch (key) {
 | 
				
			||||||
 | 
					            case "ChallengesFixVersion":
 | 
				
			||||||
 | 
					                inventory.ChallengesFixVersion = value;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case "SeasonChallengeHistory":
 | 
				
			||||||
 | 
					                value!.forEach(({ challenge, id }) => {
 | 
				
			||||||
                    const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge);
 | 
					                    const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge);
 | 
				
			||||||
                    if (itemIndex !== -1) {
 | 
					                    if (itemIndex !== -1) {
 | 
				
			||||||
                        inventory.SeasonChallengeHistory[itemIndex].id = id;
 | 
					                        inventory.SeasonChallengeHistory[itemIndex].id = id;
 | 
				
			||||||
@ -34,6 +39,15 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
 | 
				
			|||||||
                        inventory.SeasonChallengeHistory.push({ challenge, id });
 | 
					                        inventory.SeasonChallengeHistory.push({ challenge, id });
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case "ChallengeProgress":
 | 
				
			||||||
 | 
					            case "SeasonChallengeCompletions":
 | 
				
			||||||
 | 
					            case "ChallengePTS":
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            default:
 | 
				
			||||||
 | 
					                logger.warn(`unknown challenge progress entry`, { key, value });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -43,6 +57,7 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface IUpdateChallengeProgressRequest {
 | 
					interface IUpdateChallengeProgressRequest {
 | 
				
			||||||
 | 
					    ChallengePTS?: number;
 | 
				
			||||||
    ChallengesFixVersion?: number;
 | 
					    ChallengesFixVersion?: number;
 | 
				
			||||||
    ChallengeProgress?: IChallengeProgress[];
 | 
					    ChallengeProgress?: IChallengeProgress[];
 | 
				
			||||||
    SeasonChallengeHistory?: ISeasonChallenge[];
 | 
					    SeasonChallengeHistory?: ISeasonChallenge[];
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user