For bootstrapper v0.11.11, out now. Reviewed-on: #2735 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
		
			
				
	
	
		
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { getInventory } from "../../services/inventoryService.ts";
 | 
						|
import { getAccountIdForRequest } from "../../services/loginService.ts";
 | 
						|
import type { RequestHandler } from "express";
 | 
						|
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
 | 
						|
 | 
						|
export const setEvolutionProgressController: RequestHandler = async (req, res) => {
 | 
						|
    const accountId = await getAccountIdForRequest(req);
 | 
						|
    const inventory = await getInventory(accountId);
 | 
						|
    const payload = req.body as ISetEvolutionProgressRequest;
 | 
						|
 | 
						|
    inventory.EvolutionProgress ??= [];
 | 
						|
    payload.forEach(element => {
 | 
						|
        const entry = inventory.EvolutionProgress!.find(entry => entry.ItemType === element.ItemType);
 | 
						|
 | 
						|
        if (entry) {
 | 
						|
            entry.Progress = 0;
 | 
						|
            entry.Rank = element.Rank;
 | 
						|
        } else {
 | 
						|
            inventory.EvolutionProgress!.push({
 | 
						|
                Progress: 0,
 | 
						|
                Rank: element.Rank,
 | 
						|
                ItemType: element.ItemType
 | 
						|
            });
 | 
						|
        }
 | 
						|
    });
 | 
						|
 | 
						|
    await inventory.save();
 | 
						|
    res.end();
 | 
						|
    broadcastInventoryUpdate(req);
 | 
						|
};
 | 
						|
 | 
						|
type ISetEvolutionProgressRequest = {
 | 
						|
    ItemType: string;
 | 
						|
    Rank: number;
 | 
						|
}[];
 |