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

This commit is contained in:
Sainan 2025-01-19 01:58:24 +01:00 committed by GitHub
parent 7af5cd9811
commit 16c2b8f83c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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");
}