chore: use SubdocumentArray.id in some more places (#1400)

Reviewed-on: OpenWF/SpaceNinjaServer#1400
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
Sainan 2025-03-31 04:15:32 -07:00 committed by Sainan
parent b0f0b61d49
commit 04d39ed973
9 changed files with 24 additions and 34 deletions

View File

@ -17,7 +17,7 @@ export const evolveWeaponController: RequestHandler = async (req, res) => {
recipe.ingredients.map(x => ({ ItemType: x.ItemType, ItemCount: x.ItemCount * -1 }))
);
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
const item = inventory[payload.Category].id(req.query.ItemId as string)!;
item.Features ??= 0;
item.Features |= EquipmentFeatures.INCARNON_GENESIS;
@ -39,7 +39,7 @@ export const evolveWeaponController: RequestHandler = async (req, res) => {
}
]);
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
const item = inventory[payload.Category].id(req.query.ItemId as string)!;
item.Features! &= ~EquipmentFeatures.INCARNON_GENESIS;
} else {
throw new Error(`unexpected evolve weapon action: ${payload.Action}`);

View File

@ -18,17 +18,15 @@ export const focusController: RequestHandler = async (req, res) => {
case FocusOperation.InstallLens: {
const request = JSON.parse(String(req.body)) as ILensInstallRequest;
const inventory = await getInventory(accountId);
for (const item of inventory[request.Category]) {
if (item._id.toString() == request.WeaponId) {
item.FocusLens = request.LensType;
addMiscItems(inventory, [
{
ItemType: request.LensType,
ItemCount: -1
} satisfies IMiscItem
]);
break;
}
const item = inventory[request.Category].id(request.WeaponId);
if (item) {
item.FocusLens = request.LensType;
addMiscItems(inventory, [
{
ItemType: request.LensType,
ItemCount: -1
} satisfies IMiscItem
]);
}
await inventory.save();
res.json({

View File

@ -28,7 +28,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
// shard installation
const request = getJSONfromString<IShardInstallRequest>(String(req.body));
const inventory = await getInventory(accountId);
const suit = inventory.Suits.find(suit => suit._id.toString() == request.SuitId.$oid)!;
const suit = inventory.Suits.id(request.SuitId.$oid)!;
if (!suit.ArchonCrystalUpgrades || suit.ArchonCrystalUpgrades.length != 5) {
suit.ArchonCrystalUpgrades = [{}, {}, {}, {}, {}];
}
@ -56,7 +56,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
// shard removal
const request = getJSONfromString<IShardUninstallRequest>(String(req.body));
const inventory = await getInventory(accountId);
const suit = inventory.Suits.find(suit => suit._id.toString() == request.SuitId.$oid)!;
const suit = inventory.Suits.id(request.SuitId.$oid)!;
const miscItemChanges: IMiscItem[] = [];
if (suit.ArchonCrystalUpgrades![request.Slot].Color) {

View File

@ -12,9 +12,7 @@ export const nameWeaponController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const body = getJSONfromString<INameWeaponRequest>(String(req.body));
const item = inventory[req.query.Category as string as TEquipmentKey].find(
item => item._id.toString() == (req.query.ItemId as string)
)!;
const item = inventory[req.query.Category as string as TEquipmentKey].id(req.query.ItemId as string)!;
if (body.ItemName != "") {
item.ItemName = body.ItemName;
} else {

View File

@ -6,12 +6,10 @@ import { WeaponTypeInternal } from "@/src/services/itemDataService";
export const setWeaponSkillTreeController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const inventory = await getInventory(accountId, req.query.Category as string);
const payload = getJSONfromString<ISetWeaponSkillTreeRequest>(String(req.body));
const item = inventory[req.query.Category as WeaponTypeInternal].find(
item => item._id.toString() == (req.query.ItemId as string)
)!;
const item = inventory[req.query.Category as WeaponTypeInternal].id(req.query.ItemId as string)!;
item.SkillTree = payload.SkillTree;
await inventory.save();

View File

@ -5,7 +5,7 @@ import { getInventory } from "@/src/services/inventoryService";
export const popArchonCrystalUpgradeController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const suit = inventory.Suits.find(suit => suit._id.toString() == (req.query.oid as string));
const suit = inventory.Suits.id(req.query.oid as string);
if (suit && suit.ArchonCrystalUpgrades) {
suit.ArchonCrystalUpgrades = suit.ArchonCrystalUpgrades.filter(
x => x.UpgradeType != (req.query.type as string)

View File

@ -5,7 +5,7 @@ import { getInventory } from "@/src/services/inventoryService";
export const pushArchonCrystalUpgradeController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const suit = inventory.Suits.find(suit => suit._id.toString() == (req.query.oid as string));
const suit = inventory.Suits.id(req.query.oid as string);
if (suit) {
suit.ArchonCrystalUpgrades ??= [];
const count = (req.query.count as number | undefined) ?? 1;

View File

@ -84,9 +84,7 @@ export const handleInventoryItemConfigChange = async (
continue;
}
const oldLoadoutConfig = loadout[loadoutSlot].find(
loadout => loadout._id.toString() === loadoutId
);
const oldLoadoutConfig = loadout[loadoutSlot].id(loadoutId);
const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig;
const loadoutConfigDatabase: ILoadoutConfigDatabase = {

View File

@ -61,19 +61,17 @@ export const handleSetShipDecorations = async (
if (placedDecoration.MoveId) {
//moved within the same room
if (placedDecoration.OldRoom === placedDecoration.Room) {
const existingDecorationIndex = roomToPlaceIn.PlacedDecos.findIndex(
deco => deco._id.toString() === placedDecoration.MoveId
);
const existingDecoration = roomToPlaceIn.PlacedDecos.id(placedDecoration.MoveId);
if (existingDecorationIndex === -1) {
if (!existingDecoration) {
throw new Error("decoration to be moved not found");
}
roomToPlaceIn.PlacedDecos[existingDecorationIndex].Pos = placedDecoration.Pos;
roomToPlaceIn.PlacedDecos[existingDecorationIndex].Rot = placedDecoration.Rot;
existingDecoration.Pos = placedDecoration.Pos;
existingDecoration.Rot = placedDecoration.Rot;
if (placedDecoration.Scale) {
roomToPlaceIn.PlacedDecos[existingDecorationIndex].Scale = placedDecoration.Scale;
existingDecoration.Scale = placedDecoration.Scale;
}
await personalRooms.save();