chore: use MongooseDocumentArray.id instead of .find where possible #813

Merged
Sainan merged 1 commits from id into main 2025-01-18 16:58:24 -08:00
5 changed files with 9 additions and 9 deletions

View File

@ -8,7 +8,7 @@ export const arcaneCommonController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
const json = getJSONfromString(String(req.body)) as IArcaneCommonRequest; const json = getJSONfromString(String(req.body)) as IArcaneCommonRequest;
const inventory = await getInventory(accountId); 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) { if (json.newRank == -1) {
// Break down request? // Break down request?
if (!upgrade || !upgrade.UpgradeFingerprint) { if (!upgrade || !upgrade.UpgradeFingerprint) {

View File

@ -229,7 +229,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
resource.Count -= ingredient.ItemCount; 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); inventory.Suits.pull(suit);
const consumedSuit: IConsumedSuit = { s: suit.ItemType }; const consumedSuit: IConsumedSuit = { s: suit.ItemType };
if (suit.Configs && suit.Configs[0] && suit.Configs[0].pricol) { if (suit.Configs && suit.Configs[0] && suit.Configs[0].pricol) {
@ -285,7 +285,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
case "u": { case "u": {
const request = getJSONfromString(String(req.body)) as IHelminthInvigorationRequest; const request = getJSONfromString(String(req.body)) as IHelminthInvigorationRequest;
const inventory = await getInventory(accountId); 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); const upgradesExpiry = new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000);
suit.OffensiveUpgrade = request.OffensiveUpgradeType; suit.OffensiveUpgrade = request.OffensiveUpgradeType;
suit.DefensiveUpgrade = request.DefensiveUpgradeType; suit.DefensiveUpgrade = request.DefensiveUpgradeType;

View File

@ -64,19 +64,19 @@ export const startRecipeController: RequestHandler = async (req, res) => {
break; break;
} }
if (type == "/Lotus/Types/Game/PowerSuits/PlayerPowerSuit") { 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; spectreLoadout.Suits = item.ItemType;
} else if (type == "/Lotus/Weapons/Tenno/Pistol/LotusPistol") { } 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.Pistols = item.ItemType;
spectreLoadout.PistolsModularParts = item.ModularParts; spectreLoadout.PistolsModularParts = item.ModularParts;
} else if (type == "/Lotus/Weapons/Tenno/LotusLongGun") { } 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.LongGuns = item.ItemType;
spectreLoadout.LongGunsModularParts = item.ModularParts; spectreLoadout.LongGunsModularParts = item.ModularParts;
} else { } else {
console.assert(type == "/Lotus/Types/Game/LotusMeleeWeapon"); 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.Melee = item.ItemType;
spectreLoadout.MeleeModularParts = item.ModularParts; spectreLoadout.MeleeModularParts = item.ModularParts;
} }

View File

@ -35,7 +35,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
if (operation.OperationType == "UOT_ABILITY_OVERRIDE") { if (operation.OperationType == "UOT_ABILITY_OVERRIDE") {
console.assert(payload.ItemCategory == "Suits"); 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 newAbilityOverride: IAbilityOverride | undefined;
let totalPercentagePointsConsumed = 0; let totalPercentagePointsConsumed = 0;

View File

@ -157,7 +157,7 @@ export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlaced
throw new Error("room not found"); 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) { if (!placedDeco) {
throw new Error("deco not found"); throw new Error("deco not found");
} }