diff --git a/.eslintrc b/.eslintrc index a4618ed1..90844d33 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,6 +22,7 @@ "@typescript-eslint/no-unsafe-assignment": "warn", "@typescript-eslint/no-explicit-any": "warn", "@typescript-eslint/no-loss-of-precision": "warn", + "@typescript-eslint/no-unnecessary-condition": "warn", "no-case-declarations": "warn", "prettier/prettier": "error", "@typescript-eslint/semi": "error", diff --git a/src/controllers/api/claimCompletedRecipeController.ts b/src/controllers/api/claimCompletedRecipeController.ts index 179327da..21beb6c0 100644 --- a/src/controllers/api/claimCompletedRecipeController.ts +++ b/src/controllers/api/claimCompletedRecipeController.ts @@ -26,9 +26,7 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) = if (!accountId) throw new Error("no account id"); const inventory = await getInventory(accountId); - const pendingRecipe = inventory.PendingRecipes.find( - recipe => recipe._id?.toString() === claimCompletedRecipeRequest.RecipeIds[0].$oid - ); + const pendingRecipe = inventory.PendingRecipes.id(claimCompletedRecipeRequest.RecipeIds[0].$oid); if (!pendingRecipe) { throw new Error(`no pending recipe found with id ${claimCompletedRecipeRequest.RecipeIds[0].$oid}`); } diff --git a/src/controllers/api/createGuildController.ts b/src/controllers/api/createGuildController.ts index 2c698995..d5ad31e9 100644 --- a/src/controllers/api/createGuildController.ts +++ b/src/controllers/api/createGuildController.ts @@ -21,7 +21,6 @@ export const createGuildController: RequestHandler = async (req, res) => { inventory.GuildId = guild._id; // Give clan key (TODO: This should only be a blueprint) - inventory.LevelKeys ??= []; inventory.LevelKeys.push({ ItemType: "/Lotus/Types/Keys/DojoKey", ItemCount: 1 diff --git a/src/controllers/api/findSessionsController.ts b/src/controllers/api/findSessionsController.ts index 6ab9ece8..70d714bb 100644 --- a/src/controllers/api/findSessionsController.ts +++ b/src/controllers/api/findSessionsController.ts @@ -10,19 +10,19 @@ export const findSessionsController: RequestHandler = (_req, res) => { logger.debug("Found ID"); const session = getSession(req.id); - if (session) res.json({ queryId: req.queryId, Sessions: session }); + if (session.length) res.json({ queryId: req.queryId, Sessions: session }); else res.json({}); } else if (req.originalSessionId != undefined) { logger.debug("Found OriginalSessionID"); const session = getSession(req.originalSessionId); - if (session) res.json({ queryId: req.queryId, Sessions: session }); + if (session.length) res.json({ queryId: req.queryId, Sessions: session }); else res.json({}); } else { logger.debug("Found SessionRequest"); const session = getSession(req); - if (session) res.json({ queryId: req.queryId, Sessions: session }); + if (session.length) res.json({ queryId: req.queryId, Sessions: session }); else res.json({}); } }; diff --git a/src/controllers/api/focusController.ts b/src/controllers/api/focusController.ts index 5468d8dd..29c92bf2 100644 --- a/src/controllers/api/focusController.ts +++ b/src/controllers/api/focusController.ts @@ -70,7 +70,7 @@ export const focusController: RequestHandler = async (req, res) => { cost += ExportFocusUpgrades[focusType].baseFocusPointCost; inventory.FocusUpgrades.push({ ItemType: focusType, Level: 0 }); } - inventory.FocusXP[focusPolarity] -= cost; + inventory.FocusXP![focusPolarity] -= cost; await inventory.save(); res.json({ FocusTypes: request.FocusTypes, @@ -88,7 +88,7 @@ export const focusController: RequestHandler = async (req, res) => { const focusUpgradeDb = inventory.FocusUpgrades.find(entry => entry.ItemType == focusUpgrade.ItemType)!; focusUpgradeDb.Level = focusUpgrade.Level; } - inventory.FocusXP[focusPolarity] -= cost; + inventory.FocusXP![focusPolarity] -= cost; await inventory.save(); res.json({ FocusInfos: request.FocusInfos, @@ -113,7 +113,7 @@ export const focusController: RequestHandler = async (req, res) => { const request = JSON.parse(String(req.body)) as IUnbindUpgradeRequest; const focusPolarity = focusTypeToPolarity(request.FocusTypes[0]); const inventory = await getInventory(accountId); - inventory.FocusXP[focusPolarity] -= 750_000 * request.FocusTypes.length; + inventory.FocusXP![focusPolarity] -= 750_000 * request.FocusTypes.length; addMiscItems(inventory, [ { ItemType: "/Lotus/Types/Gameplay/Eidolon/Resources/SentientShards/SentientShardBrilliantItem", diff --git a/src/controllers/api/gildWeaponController.ts b/src/controllers/api/gildWeaponController.ts index 319da457..5a89415f 100644 --- a/src/controllers/api/gildWeaponController.ts +++ b/src/controllers/api/gildWeaponController.ts @@ -34,9 +34,6 @@ export const gildWeaponController: RequestHandler = async (req, res) => { data.Category = req.query.Category as WeaponTypeInternal | "Hoverboards"; const inventory = await getInventory(accountId); - if (!inventory[data.Category]) { - throw new Error(`Category ${String(req.query.Category)} not found in inventory`); - } const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId); if (weaponIndex === -1) { throw new Error(`Weapon with ${data.ItemId} not found in category ${String(req.query.Category)}`); diff --git a/src/controllers/api/infestedFoundryController.ts b/src/controllers/api/infestedFoundryController.ts index 166cafc1..61a74982 100644 --- a/src/controllers/api/infestedFoundryController.ts +++ b/src/controllers/api/infestedFoundryController.ts @@ -239,7 +239,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => { inventory.InfestedFoundry!.Slots!--; } inventory.InfestedFoundry!.ConsumedSuits ??= []; - inventory.InfestedFoundry!.ConsumedSuits?.push(consumedSuit); + inventory.InfestedFoundry!.ConsumedSuits.push(consumedSuit); inventory.InfestedFoundry!.LastConsumedSuit = suit; inventory.InfestedFoundry!.AbilityOverrideUnlockCooldown = new Date( new Date().getTime() + 24 * 60 * 60 * 1000 diff --git a/src/controllers/api/queueDojoComponentDestructionController.ts b/src/controllers/api/queueDojoComponentDestructionController.ts index 5c951ffc..da84c40f 100644 --- a/src/controllers/api/queueDojoComponentDestructionController.ts +++ b/src/controllers/api/queueDojoComponentDestructionController.ts @@ -9,12 +9,10 @@ export const queueDojoComponentDestructionController: RequestHandler = async (re guild.DojoComponents!.findIndex(x => x._id.toString() === componentId), 1 )[0]; - if (component) { - const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf); - if (room) { - guild.DojoCapacity -= room.capacity; - guild.DojoEnergy -= room.energy; - } + const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf); + if (room) { + guild.DojoCapacity -= room.capacity; + guild.DojoEnergy -= room.energy; } await guild.save(); res.json({ diff --git a/src/controllers/api/startRecipeController.ts b/src/controllers/api/startRecipeController.ts index 36e7e003..06ce6d90 100644 --- a/src/controllers/api/startRecipeController.ts +++ b/src/controllers/api/startRecipeController.ts @@ -75,6 +75,7 @@ export const startRecipeController: RequestHandler = async (req, res) => { spectreLoadout.LongGuns = item.ItemType; spectreLoadout.LongGunsModularParts = item.ModularParts; } else { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition console.assert(type == "/Lotus/Types/Game/LotusMeleeWeapon"); const item = inventory.Melee.id(oid)!; spectreLoadout.Melee = item.ItemType; diff --git a/src/controllers/api/syndicateSacrificeController.ts b/src/controllers/api/syndicateSacrificeController.ts index 5feef499..e1be3510 100644 --- a/src/controllers/api/syndicateSacrificeController.ts +++ b/src/controllers/api/syndicateSacrificeController.ts @@ -22,7 +22,7 @@ export const syndicateSacrificeController: RequestHandler = async (request, resp InventoryChanges: {}, Level: data.SacrificeLevel, LevelIncrease: level <= 0 ? 1 : level, - NewEpisodeReward: syndicate?.Tag == "RadioLegionIntermission9Syndicate" + NewEpisodeReward: syndicate.Tag == "RadioLegionIntermission9Syndicate" }; const manifest = ExportSyndicates[data.AffiliationTag]; diff --git a/src/controllers/stats/viewController.ts b/src/controllers/stats/viewController.ts index 7a01365d..e5122699 100644 --- a/src/controllers/stats/viewController.ts +++ b/src/controllers/stats/viewController.ts @@ -9,10 +9,6 @@ import { getInventory } from "@/src/services/inventoryService"; const viewController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); const inventory = await getInventory(accountId, "XPInfo"); - if (!inventory) { - res.status(400).json({ error: "inventory was undefined" }); - return; - } const responseJson: IStatsView = {}; responseJson.Weapons = []; diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index df3e2b78..b9ee0bb7 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -50,13 +50,7 @@ export const getWeaponType = (weaponName: string): WeaponTypeInternal => { throw new Error(`${weaponName} doesn't quack like a weapon`); } - const weaponType = weaponInfo.productCategory; - - if (!weaponType) { - throw new Error(`unknown weapon category for item ${weaponName}`); - } - - return weaponType; + return weaponInfo.productCategory; }; export const getRecipe = (uniqueName: string): IRecipe | undefined => { diff --git a/src/services/saveLoadoutService.ts b/src/services/saveLoadoutService.ts index a50b1434..204bbe00 100644 --- a/src/services/saveLoadoutService.ts +++ b/src/services/saveLoadoutService.ts @@ -44,7 +44,7 @@ export const handleInventoryItemConfigChange = async ( // all non-empty entries are one loadout slot for (const [loadoutId, loadoutConfig] of Object.entries(operatorConfig)) { logger.debug(`loadoutId ${loadoutId} loadoutConfig`, { config: loadoutConfig }); - const loadout = operatorLoadout.find(loadout => loadout._id?.toString() === loadoutId); + const loadout = operatorLoadout.id(loadoutId); // if no config with this id exists, create a new one if (!loadout) { @@ -109,7 +109,7 @@ export const handleInventoryItemConfigChange = async ( } const loadoutIndex = loadout[loadoutSlot].indexOf(oldLoadoutConfig); - if (loadoutIndex === undefined || loadoutIndex === -1) { + if (loadoutIndex === -1) { throw new Error("loadout index not found"); } diff --git a/src/services/shipCustomizationsService.ts b/src/services/shipCustomizationsService.ts index 03336fc8..c583c1a8 100644 --- a/src/services/shipCustomizationsService.ts +++ b/src/services/shipCustomizationsService.ts @@ -55,7 +55,7 @@ export const handleSetShipDecorations = async ( if (placedDecoration.MoveId) { //moved within the same room if (placedDecoration.OldRoom === placedDecoration.Room) { - const existingDecorationIndex = roomToPlaceIn?.PlacedDecos?.findIndex( + const existingDecorationIndex = roomToPlaceIn.PlacedDecos.findIndex( deco => deco._id.toString() === placedDecoration.MoveId ); @@ -136,7 +136,7 @@ export const handleSetShipDecorations = async ( //place decoration const decoId = new Types.ObjectId(); - roomToPlaceIn.PlacedDecos?.push({ + roomToPlaceIn.PlacedDecos.push({ Type: placedDecoration.Type, Pos: placedDecoration.Pos, Rot: placedDecoration.Rot, @@ -157,7 +157,7 @@ export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlaced throw new Error("room not found"); } - const placedDeco = room.PlacedDecos?.id(req.DecoId); + const placedDeco = room.PlacedDecos.id(req.DecoId); if (!placedDeco) { throw new Error("deco not found"); } diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index d5af0066..e0e446f9 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -255,7 +255,7 @@ export interface IInventoryClient extends IDailyAffiliations { SpectreLoadouts?: ISpectreLoadout[]; EmailItems: ITypeCount[]; CompletedSyndicates: string[]; - FocusXP: IFocusXP; + FocusXP?: IFocusXP; Wishlist: string[]; Alignment: IAlignment; CompletedSorties: string[]; @@ -267,7 +267,7 @@ export interface IInventoryClient extends IDailyAffiliations { ShipDecorations: IConsumable[]; DiscoveredMarkers: IDiscoveredMarker[]; CompletedJobs: ICompletedJob[]; - FocusAbility: string; + FocusAbility?: string; FocusUpgrades: IFocusUpgrade[]; HasContributedToDojo?: boolean; HWIDProtectEnabled?: boolean;