Implement installation of Focus Lenses #550
@ -1,7 +1,7 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { getInventory, addMiscItems, addEquipment } from "@/src/services/inventoryService";
|
||||
import { IMiscItem, TFocusPolarity } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { IMiscItem, TFocusPolarity, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { ExportFocusUpgrades } from "warframe-public-export-plus";
|
||||
|
||||
@ -14,6 +14,28 @@ export const focusController: RequestHandler = async (req, res) => {
|
||||
logger.debug(req.body.toString());
|
||||
res.end();
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
await inventory.save();
|
||||
res.json({
|
||||
weaponId: request.WeaponId,
|
||||
lensType: request.LensType
|
||||
});
|
||||
break;
|
||||
}
|
||||
case FocusOperation.UnlockWay: {
|
||||
const focusType = (JSON.parse(String(req.body)) as IWayRequest).FocusType;
|
||||
const focusPolarity = focusTypeToPolarity(focusType);
|
||||
@ -144,6 +166,7 @@ export const focusController: RequestHandler = async (req, res) => {
|
||||
};
|
||||
|
||||
enum FocusOperation {
|
||||
InstallLens = "1",
|
||||
UnlockWay = "2",
|
||||
UnlockUpgrade = "3",
|
||||
LevelUpUpgrade = "4",
|
||||
@ -186,6 +209,12 @@ interface ISentTrainingAmplifierRequest {
|
||||
StartingWeaponType: string;
|
||||
}
|
||||
|
||||
interface ILensInstallRequest {
|
||||
LensType: string;
|
||||
Category: TEquipmentKey;
|
||||
WeaponId: string;
|
||||
}
|
||||
|
||||
// Works for ways & upgrades
|
||||
const focusTypeToPolarity = (type: string): TFocusPolarity => {
|
||||
return ("AP_" + type.substr(1).split("/")[3].toUpperCase()) as TFocusPolarity;
|
||||
|
Loading…
x
Reference in New Issue
Block a user
⚠️ Potential issue
Validate request body and handle parsing errors
Currently, the code directly parses
req.body
usingJSON.parse(String(req.body))
without any error handling or validation. If the request body is malformed or missing required fields, this could result in a runtime error or unexpected behavior.Consider adding error handling to manage JSON parsing errors and validate that all necessary properties are present and correctly typed in
ILensInstallRequest
.Apply this diff to handle parsing errors and validate the request:
📝 Committable suggestion