From 16c2b8f83c1c5f0d67ec0f856533f43b30cb1f68 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 19 Jan 2025 01:58:24 +0100 Subject: [PATCH] chore: use MongooseDocumentArray.id instead of .find where possible (#813) --- src/controllers/api/arcaneCommonController.ts | 2 +- src/controllers/api/infestedFoundryController.ts | 4 ++-- src/controllers/api/startRecipeController.ts | 8 ++++---- src/controllers/api/upgradesController.ts | 2 +- src/services/shipCustomizationsService.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/controllers/api/arcaneCommonController.ts b/src/controllers/api/arcaneCommonController.ts index 671027467..2caccc29e 100644 --- a/src/controllers/api/arcaneCommonController.ts +++ b/src/controllers/api/arcaneCommonController.ts @@ -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) { diff --git a/src/controllers/api/infestedFoundryController.ts b/src/controllers/api/infestedFoundryController.ts index 35b0d3d90..f7567b01f 100644 --- a/src/controllers/api/infestedFoundryController.ts +++ b/src/controllers/api/infestedFoundryController.ts @@ -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; diff --git a/src/controllers/api/startRecipeController.ts b/src/controllers/api/startRecipeController.ts index 4a5113154..36e7e003a 100644 --- a/src/controllers/api/startRecipeController.ts +++ b/src/controllers/api/startRecipeController.ts @@ -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; } diff --git a/src/controllers/api/upgradesController.ts b/src/controllers/api/upgradesController.ts index eea06d2e0..bbfd29923 100644 --- a/src/controllers/api/upgradesController.ts +++ b/src/controllers/api/upgradesController.ts @@ -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; diff --git a/src/services/shipCustomizationsService.ts b/src/services/shipCustomizationsService.ts index 2d3ab5b55..03336fc8a 100644 --- a/src/services/shipCustomizationsService.ts +++ b/src/services/shipCustomizationsService.ts @@ -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"); }