missionInventoryUpdate - error handler
This commit is contained in:
		
							parent
							
								
									17ae269e00
								
							
						
					
					
						commit
						856d3c1ccb
					
				@ -1,5 +1,6 @@
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { missionInventoryUpdate } from "@/src/services/inventoryService";
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
/*
 | 
			
		||||
- [ ]  crossPlaySetting
 | 
			
		||||
- [ ]  rewardsMultiplier
 | 
			
		||||
@ -39,11 +40,27 @@ import { missionInventoryUpdate } from "@/src/services/inventoryService";
 | 
			
		||||
- [ ]  FpsSamples
 | 
			
		||||
*/
 | 
			
		||||
const missionInventoryUpdateController: RequestHandler = async (req, res) => {
 | 
			
		||||
    fs.writeFile("./tmp/missionInventoryUpdate", req.body,(err)=>{
 | 
			
		||||
        if(err)
 | 
			
		||||
            return console.log(err);
 | 
			
		||||
    });  // temp log, !!! tmp folder need on main dir
 | 
			
		||||
 | 
			
		||||
    const [data, _secondIGuessIsSalt] = String(req.body).split("\n");
 | 
			
		||||
    const id = req.query.accountId as string;
 | 
			
		||||
    
 | 
			
		||||
    await missionInventoryUpdate(JSON.parse(data), id);
 | 
			
		||||
 | 
			
		||||
    // TODO - salt check
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
        const parsedData = JSON.parse(data);
 | 
			
		||||
        if (typeof parsedData !== 'object' || parsedData === null)
 | 
			
		||||
            throw new Error('Invalid data format');
 | 
			
		||||
    
 | 
			
		||||
        await missionInventoryUpdate(parsedData, id);
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
        console.error('Error parsing JSON data:', err);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO - get original response
 | 
			
		||||
    res.json({});
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -111,6 +111,8 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
 | 
			
		||||
    const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits } = data;
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
 | 
			
		||||
    // TODO - multipliers logic
 | 
			
		||||
 | 
			
		||||
    const addGearExpByCategory = (gearArray: MissionInventoryUpdateGear[] | undefined, categoryName: 'Pistols'|'LongGuns'|'Melee'|'Suits') => {
 | 
			
		||||
        const category = inventory[categoryName];
 | 
			
		||||
 | 
			
		||||
@ -127,7 +129,7 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
 | 
			
		||||
 | 
			
		||||
    const addItemsByCategory = (itemsArray: (MissionInventoryUpdateItem | MissionInventoryUpdateCard)[] | undefined, categoryName: 'RawUpgrades'|'MiscItems') => {
 | 
			
		||||
        const category = inventory[categoryName];
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
			
		||||
            const itemIndex = category.findIndex(i => i.ItemType === ItemType);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user