chore: do addItem on inventory document, not accountId #699

Merged
Sainan merged 11 commits from additem-inplace into main 2025-01-03 15:25:09 -08:00
Showing only changes of commit f6afdd4869 - Show all commits

View File

@ -143,11 +143,10 @@ export const addItem = async (
}
};
} else if (ExportResources[typeName].productCategory == "CrewShips") {
return {
InventoryChanges: {
CrewShips: [await addCrewShip(typeName, accountId)]
}
};
const inventory = await getInventory(accountId);
const inventoryChanges = addCrewShip(inventory, typeName);
await inventory.save();
return { InventoryChanges: inventoryChanges };
} else {
const miscItemChanges = [
{
@ -590,11 +589,15 @@ export const addSkin = async (typeName: string, accountId: string): Promise<IWea
return changedInventory.WeaponSkins[index].toJSON() as object as IWeaponSkinClient;
};
const addCrewShip = async (typeName: string, accountId: string) => {
const inventory = await getInventory(accountId);
const addCrewShip = (
inventory: TInventoryDatabaseDocument,
typeName: string,
inventoryChanges: IInventoryChanges = {}
): IInventoryChanges => {
const index = inventory.CrewShips.push({ ItemType: typeName }) - 1;
const changedInventory = await inventory.save();
return changedInventory.CrewShips[index].toJSON();
inventoryChanges.CrewShips ??= [];
(inventoryChanges.CrewShips as object[]).push(inventory.CrewShips[index].toJSON());
return inventoryChanges;
};
const addGearExpByCategory = (