forked from OpenWF/SpaceNinjaServer
		
	feat: fish dissection (#663)
This commit is contained in:
		
							parent
							
								
									7ea02d142f
								
							
						
					
					
						commit
						d930c3d957
					
				
							
								
								
									
										38
									
								
								src/controllers/api/fishmongerController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/controllers/api/fishmongerController.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { ExportResources } from "warframe-public-export-plus";
 | 
			
		||||
 | 
			
		||||
export const fishmongerController: RequestHandler = async (req, res) => {
 | 
			
		||||
    if (!req.query.dissect) {
 | 
			
		||||
        throw new Error("expected fishmonger request to be for dissection");
 | 
			
		||||
    }
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
    const body = getJSONfromString(String(req.body)) as IFishmongerRequest;
 | 
			
		||||
    const miscItemChanges: IMiscItem[] = [];
 | 
			
		||||
    for (const fish of body.Fish) {
 | 
			
		||||
        for (const part of ExportResources[fish.ItemType].dissectionParts!) {
 | 
			
		||||
            const partItem = miscItemChanges.find(x => x.ItemType == part.ItemType);
 | 
			
		||||
            if (partItem) {
 | 
			
		||||
                partItem.ItemCount += part.ItemCount;
 | 
			
		||||
            } else {
 | 
			
		||||
                miscItemChanges.push(part);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        miscItemChanges.push({ ItemType: fish.ItemType, ItemCount: fish.ItemCount * -1 });
 | 
			
		||||
    }
 | 
			
		||||
    addMiscItems(inventory, miscItemChanges);
 | 
			
		||||
    await inventory.save();
 | 
			
		||||
    res.json({
 | 
			
		||||
        InventoryChanges: {
 | 
			
		||||
            MiscItems: miscItemChanges
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
interface IFishmongerRequest {
 | 
			
		||||
    Fish: IMiscItem[];
 | 
			
		||||
}
 | 
			
		||||
@ -11,6 +11,7 @@ import { dronesController } from "@/src/controllers/api/dronesController";
 | 
			
		||||
import { endlessXpController } from "@/src/controllers/api/endlessXpController";
 | 
			
		||||
import { evolveWeaponController } from "@/src/controllers/api/evolveWeaponController";
 | 
			
		||||
import { findSessionsController } from "@/src/controllers/api/findSessionsController";
 | 
			
		||||
import { fishmongerController } from "@/src/controllers/api/fishmongerController";
 | 
			
		||||
import { focusController } from "@/src/controllers/api/focusController";
 | 
			
		||||
import { fusionTreasuresController } from "@/src/controllers/api/fusionTreasuresController";
 | 
			
		||||
import { genericUpdateController } from "@/src/controllers/api/genericUpdateController";
 | 
			
		||||
@ -113,6 +114,7 @@ apiRouter.post("/createGuild.php", createGuildController);
 | 
			
		||||
apiRouter.post("/endlessXp.php", endlessXpController);
 | 
			
		||||
apiRouter.post("/evolveWeapon.php", evolveWeaponController);
 | 
			
		||||
apiRouter.post("/findSessions.php", findSessionsController);
 | 
			
		||||
apiRouter.post("/fishmonger.php", fishmongerController);
 | 
			
		||||
apiRouter.post("/focus.php", focusController);
 | 
			
		||||
apiRouter.post("/fusionTreasures.php", fusionTreasuresController);
 | 
			
		||||
apiRouter.post("/genericUpdate.php", genericUpdateController);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user