feat: implement purchasing of formas, potatoes, etc.

This commit is contained in:
Sainan 2024-05-05 13:52:14 +02:00
parent 6798e09b50
commit 19ba136c08

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