improve: purchases #161

Merged
Sainan merged 7 commits from stonks into main 2024-05-08 16:27:33 -07:00
Showing only changes of commit 19ba136c08 - Show all commits

View File

@ -5,12 +5,15 @@ import {
addBooster,
addCustomization,
addMechSuit,
addMiscItems,
addPowerSuit,
addSentinel,
addWeapon,
getInventory,
updateCurrency,
updateSlots
} from "@/src/services/inventoryService";
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
import { IPurchaseRequest, IPurchaseResponse, SlotNameToInventoryName, SlotPurchase } from "@/src/types/purchaseTypes";
import { logger } from "@/src/utils/logger";
@ -179,6 +182,8 @@ const handleTypesPurchase = async (typesName: string, accountId: string) => {
return await handleSentinelPurchase(typesName, accountId);
case "SlotItems":
return await handleSlotPurchase(typesName, accountId);
case "Items":
return await handleMiscItemPurchase(typesName, accountId);
default:
throw new Error(`unknown Types category: ${typeCategory} not implemented or new`);
}
@ -232,3 +237,20 @@ const handleBoostersPurchase = async (boosterStoreName: string, accountId: strin
}
};
};
const handleMiscItemPurchase = async (uniqueName: string, accountId: string) => {
const inventory = await getInventory(accountId);
const miscItemChanges = [
{
ItemType: uniqueName,
ItemCount: 1
} satisfies IMiscItem
];
addMiscItems(inventory, miscItemChanges);
await inventory.save();
return {
InventoryChanges: {
MiscItems: miscItemChanges
}
};
};