forked from OpenWF/SpaceNinjaServer
chore: get rid of some unecessary conditionals (#835)
This commit is contained in:
parent
c9b48ace36
commit
a4c44e8bb0
@ -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",
|
||||
|
@ -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}`);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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({});
|
||||
}
|
||||
};
|
||||
|
@ -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",
|
||||
|
@ -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)}`);
|
||||
|
@ -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
|
||||
|
@ -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({
|
||||
|
@ -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;
|
||||
|
@ -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];
|
||||
|
@ -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 = [];
|
||||
|
@ -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 => {
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user