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