chore: use MongooseDocumentArray.id instead of .find where possible (#813)
This commit is contained in:
		
							parent
							
								
									7af5cd9811
								
							
						
					
					
						commit
						16c2b8f83c
					
				@ -8,7 +8,7 @@ export const arcaneCommonController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
    const json = getJSONfromString(String(req.body)) as IArcaneCommonRequest;
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
    const upgrade = inventory.Upgrades.find(x => x._id!.toString() == json.arcane.ItemId.$oid);
 | 
			
		||||
    const upgrade = inventory.Upgrades.id(json.arcane.ItemId.$oid);
 | 
			
		||||
    if (json.newRank == -1) {
 | 
			
		||||
        // Break down request?
 | 
			
		||||
        if (!upgrade || !upgrade.UpgradeFingerprint) {
 | 
			
		||||
 | 
			
		||||
@ -229,7 +229,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
 | 
			
		||||
                    resource.Count -= ingredient.ItemCount;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            const suit = inventory.Suits.find(x => x._id.toString() == request.SuitId.$oid)!;
 | 
			
		||||
            const suit = inventory.Suits.id(request.SuitId.$oid)!;
 | 
			
		||||
            inventory.Suits.pull(suit);
 | 
			
		||||
            const consumedSuit: IConsumedSuit = { s: suit.ItemType };
 | 
			
		||||
            if (suit.Configs && suit.Configs[0] && suit.Configs[0].pricol) {
 | 
			
		||||
@ -285,7 +285,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
 | 
			
		||||
        case "u": {
 | 
			
		||||
            const request = getJSONfromString(String(req.body)) as IHelminthInvigorationRequest;
 | 
			
		||||
            const inventory = await getInventory(accountId);
 | 
			
		||||
            const suit = inventory.Suits.find(x => x._id.toString() == request.SuitId.$oid)!;
 | 
			
		||||
            const suit = inventory.Suits.id(request.SuitId.$oid)!;
 | 
			
		||||
            const upgradesExpiry = new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000);
 | 
			
		||||
            suit.OffensiveUpgrade = request.OffensiveUpgradeType;
 | 
			
		||||
            suit.DefensiveUpgrade = request.DefensiveUpgradeType;
 | 
			
		||||
 | 
			
		||||
@ -64,19 +64,19 @@ export const startRecipeController: RequestHandler = async (req, res) => {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            if (type == "/Lotus/Types/Game/PowerSuits/PlayerPowerSuit") {
 | 
			
		||||
                const item = inventory.Suits.find(x => x._id.toString() == oid)!;
 | 
			
		||||
                const item = inventory.Suits.id(oid)!;
 | 
			
		||||
                spectreLoadout.Suits = item.ItemType;
 | 
			
		||||
            } else if (type == "/Lotus/Weapons/Tenno/Pistol/LotusPistol") {
 | 
			
		||||
                const item = inventory.Pistols.find(x => x._id.toString() == oid)!;
 | 
			
		||||
                const item = inventory.Pistols.id(oid)!;
 | 
			
		||||
                spectreLoadout.Pistols = item.ItemType;
 | 
			
		||||
                spectreLoadout.PistolsModularParts = item.ModularParts;
 | 
			
		||||
            } else if (type == "/Lotus/Weapons/Tenno/LotusLongGun") {
 | 
			
		||||
                const item = inventory.LongGuns.find(x => x._id.toString() == oid)!;
 | 
			
		||||
                const item = inventory.LongGuns.id(oid)!;
 | 
			
		||||
                spectreLoadout.LongGuns = item.ItemType;
 | 
			
		||||
                spectreLoadout.LongGunsModularParts = item.ModularParts;
 | 
			
		||||
            } else {
 | 
			
		||||
                console.assert(type == "/Lotus/Types/Game/LotusMeleeWeapon");
 | 
			
		||||
                const item = inventory.Melee.find(x => x._id.toString() == oid)!;
 | 
			
		||||
                const item = inventory.Melee.id(oid)!;
 | 
			
		||||
                spectreLoadout.Melee = item.ItemType;
 | 
			
		||||
                spectreLoadout.MeleeModularParts = item.ModularParts;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
 | 
			
		||||
 | 
			
		||||
        if (operation.OperationType == "UOT_ABILITY_OVERRIDE") {
 | 
			
		||||
            console.assert(payload.ItemCategory == "Suits");
 | 
			
		||||
            const suit = inventory.Suits.find(x => x._id.toString() == payload.ItemId.$oid)!;
 | 
			
		||||
            const suit = inventory.Suits.id(payload.ItemId.$oid)!;
 | 
			
		||||
 | 
			
		||||
            let newAbilityOverride: IAbilityOverride | undefined;
 | 
			
		||||
            let totalPercentagePointsConsumed = 0;
 | 
			
		||||
 | 
			
		||||
@ -157,7 +157,7 @@ export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlaced
 | 
			
		||||
        throw new Error("room not found");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const placedDeco = room.PlacedDecos?.find(x => x._id.toString() == req.DecoId);
 | 
			
		||||
    const placedDeco = room.PlacedDecos?.id(req.DecoId);
 | 
			
		||||
    if (!placedDeco) {
 | 
			
		||||
        throw new Error("deco not found");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user