feat(webui): more equipment #826

Merged
AMelonInsideLemon merged 3 commits from webui-more-equipment into main 2025-01-19 06:03:34 -08:00
2 changed files with 16 additions and 16 deletions
Showing only changes of commit 463a7d8f14 - Show all commits

View File

@ -1,6 +1,7 @@
import { getAccountIdForRequest } from "@/src/services/loginService";
import { addEquipment, addPowerSuit, getInventory, updateSlots } from "@/src/services/inventoryService";
import { productCategoryToSlotName } from "@/src/helpers/purchaseHelpers";
import { SlotNames } from "@/src/types/purchaseTypes";
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
import { RequestHandler } from "express";
export const addItemsController: RequestHandler = async (req, res) => {
@ -24,9 +25,22 @@ export const addItemsController: RequestHandler = async (req, res) => {
res.end();
};
const productCategoryToSlotName: Record<ItemType, SlotNames> = {
coderabbitai[bot] commented 2025-01-19 05:39:27 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Add error handling for unknown item types.

The default case assumes the item type exists in productCategoryToSlotName. Add validation to prevent runtime errors.

 default:
+    if (!(request.type in productCategoryToSlotName)) {
+        throw new Error(`Unknown item type: ${request.type}`);
+    }
     updateSlots(inventory, productCategoryToSlotName[request.type], 0, 1);
     addEquipment(inventory, request.type, request.internalName);
     break;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

            default:
                if (!(request.type in productCategoryToSlotName)) {
                    throw new Error(`Unknown item type: ${request.type}`);
                }
                updateSlots(inventory, productCategoryToSlotName[request.type], 0, 1);
                addEquipment(inventory, request.type, request.internalName);
                break;
_:warning: Potential issue_ **Add error handling for unknown item types.** The default case assumes the item type exists in productCategoryToSlotName. Add validation to prevent runtime errors. ```diff default: + if (!(request.type in productCategoryToSlotName)) { + throw new Error(`Unknown item type: ${request.type}`); + } updateSlots(inventory, productCategoryToSlotName[request.type], 0, 1); addEquipment(inventory, request.type, request.internalName); break; ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion default: if (!(request.type in productCategoryToSlotName)) { throw new Error(`Unknown item type: ${request.type}`); } updateSlots(inventory, productCategoryToSlotName[request.type], 0, 1); addEquipment(inventory, request.type, request.internalName); break; ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
Suits: InventorySlot.SUITS,
Pistols: InventorySlot.WEAPONS,
Melee: InventorySlot.WEAPONS,
LongGuns: InventorySlot.WEAPONS,
SpaceSuits: InventorySlot.SPACESUITS,
SpaceGuns: InventorySlot.SPACESUITS,
SpaceMelee: InventorySlot.SPACESUITS,
Sentinels: InventorySlot.SENTINELS,
SentinelWeapons: InventorySlot.SENTINELS
};
enum ItemType {
Suits = "Suits",
SpaceSuits = "SpaceSuits",
LongGuns = "LongGuns",
Pistols = "Pistols",
Melee = "Melee",
SpaceGuns = "SpaceGuns",

View File

@ -1,6 +1,5 @@
import { slotPurchaseNameToSlotName } from "@/src/services/purchaseService";
import { SlotNames, SlotPurchaseName } from "@/src/types/purchaseTypes";
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
import { SlotPurchaseName } from "@/src/types/purchaseTypes";
export const isSlotPurchaseName = (slotPurchaseName: string): slotPurchaseName is SlotPurchaseName => {
return slotPurchaseName in slotPurchaseNameToSlotName;
@ -10,16 +9,3 @@ export const parseSlotPurchaseName = (slotPurchaseName: string): SlotPurchaseNam
if (!isSlotPurchaseName(slotPurchaseName)) throw new Error(`invalid slot name ${slotPurchaseName}`);
return slotPurchaseName;
};
export const productCategoryToSlotName: Record<string, SlotNames> = {
Suits: InventorySlot.SUITS,
Pistols: InventorySlot.WEAPONS,
Melee: InventorySlot.WEAPONS,
LongGuns: InventorySlot.WEAPONS,
SpaceSuits: InventorySlot.SPACESUITS,
SpaceGuns: InventorySlot.SPACESUITS,
SpaceMelee: InventorySlot.SPACESUITS,
Sentinels: InventorySlot.SENTINELS,
SentinelWeapons: InventorySlot.SENTINELS,
MechSuits: InventorySlot.MECHSUITS
};