chore: fix misc eslint warnings

This commit is contained in:
Sainan 2024-10-17 22:50:34 +02:00
parent ad6c24de71
commit 0facf666fe
13 changed files with 30 additions and 23 deletions

View File

@ -10,7 +10,7 @@ const artifactsController: RequestHandler = async (req, res) => {
try { try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
const artifactsData = getJSONfromString(req.body.toString()) as IArtifactsRequest; const artifactsData = getJSONfromString(String(req.body)) as IArtifactsRequest;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const upgradeModId = await upgradeMod(artifactsData, accountId); const upgradeModId = await upgradeMod(artifactsData, accountId);
res.send(upgradeModId); res.send(upgradeModId);

View File

@ -39,8 +39,8 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
const recipe = getRecipe(pendingRecipe.ItemType); const recipe = getRecipe(pendingRecipe.ItemType);
if (!recipe) { if (!recipe) {
logger.error(`no completed item found for recipe ${pendingRecipe._id}`); logger.error(`no completed item found for recipe ${pendingRecipe._id?.toString()}`);
throw new Error(`no completed item found for recipe ${pendingRecipe._id}`); throw new Error(`no completed item found for recipe ${pendingRecipe._id?.toString()}`);
} }
if (req.query.cancel) { if (req.query.cancel) {

View File

@ -10,8 +10,8 @@ export const focusController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
switch (req.query.op) { switch (req.query.op) {
default: default:
logger.error("Unhandled focus op type: " + req.query.op); logger.error("Unhandled focus op type: " + String(req.query.op));
logger.debug(req.body.toString()); logger.debug(String(req.body));
res.end(); res.end();
break; break;
case FocusOperation.InstallLens: { case FocusOperation.InstallLens: {

View File

@ -22,7 +22,7 @@ const parseFusionTreasure = (name: string, count: number): IFusionTreasure => {
export const fusionTreasuresController: RequestHandler = async (req, res) => { export const fusionTreasuresController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest; const request = JSON.parse(String(req.body)) as IFusionTreasureRequest;
const oldTreasure = parseFusionTreasure(request.oldTreasureName, -1); const oldTreasure = parseFusionTreasure(request.oldTreasureName, -1);
const newTreasure = parseFusionTreasure(request.newTreasureName, 1); const newTreasure = parseFusionTreasure(request.newTreasureName, 1);

View File

@ -133,6 +133,6 @@ export const getVendorInfoController: RequestHandler = (req, res) => {
break; break;
default: default:
throw new Error(`Unknown vendor: ${req.query.vendor}`); throw new Error(`Unknown vendor: ${String(req.query.vendor)}`);
} }
}; };

View File

@ -27,20 +27,20 @@ interface IGildWeaponRequest {
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
export const gildWeaponController: RequestHandler = async (req, res) => { export const gildWeaponController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
const data: IGildWeaponRequest = getJSONfromString(String(req.body)); const data = getJSONfromString(String(req.body)) as IGildWeaponRequest;
data.ItemId = String(req.query.ItemId); data.ItemId = String(req.query.ItemId);
if (!modularWeaponCategory.includes(req.query.Category as WeaponTypeInternal | "Hoverboards")) { if (!modularWeaponCategory.includes(req.query.Category as WeaponTypeInternal | "Hoverboards")) {
throw new Error(`Unknown modular weapon Category: ${req.query.Category}`); throw new Error(`Unknown modular weapon Category: ${String(req.query.Category)}`);
} }
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]) { if (!inventory[data.Category]) {
throw new Error(`Category ${req.query.Category} not found in inventory`); 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 ${req.query.Category}`); throw new Error(`Weapon with ${data.ItemId} not found in category ${String(req.query.Category)}`);
} }
const weapon = inventory[data.Category][weaponIndex]; const weapon = inventory[data.Category][weaponIndex];

View File

@ -59,7 +59,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
break; break;
default: default:
throw new Error(`unhandled infestedFoundry mode: ${req.query.mode}`); throw new Error(`unhandled infestedFoundry mode: ${String(req.query.mode)}`);
} }
}; };

View File

@ -51,7 +51,7 @@ const missionInventoryUpdateController: RequestHandler = async (req, res): Promi
try { try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
const lootInventory = getJSONfromString(req.body.toString()) as IMissionInventoryUpdateRequest; const lootInventory = getJSONfromString(String(req.body)) as IMissionInventoryUpdateRequest;
logger.debug("missionInventoryUpdate with lootInventory =", lootInventory); logger.debug("missionInventoryUpdate with lootInventory =", lootInventory);

View File

@ -4,6 +4,7 @@ import { getInventory } from "@/src/services/inventoryService";
import { IMongoDate } from "@/src/types/commonTypes"; import { IMongoDate } from "@/src/types/commonTypes";
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { unixTimesInMs } from "@/src/constants/timeConstants"; import { unixTimesInMs } from "@/src/constants/timeConstants";
import { IInventoryChanges } from "@/src/types/purchaseTypes";
interface ITrainingResultsRequest { interface ITrainingResultsRequest {
numLevelsGained: number; numLevelsGained: number;
@ -12,7 +13,7 @@ interface ITrainingResultsRequest {
interface ITrainingResultsResponse { interface ITrainingResultsResponse {
NewTrainingDate: IMongoDate; NewTrainingDate: IMongoDate;
NewLevel: number; NewLevel: number;
InventoryChanges: any[]; InventoryChanges: IInventoryChanges;
} }
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
@ -36,7 +37,7 @@ const trainingResultController: RequestHandler = async (req, res): Promise<void>
$date: { $numberLong: changedinventory.TrainingDate.getTime().toString() } $date: { $numberLong: changedinventory.TrainingDate.getTime().toString() }
}, },
NewLevel: trainingResults.numLevelsGained == 1 ? changedinventory.PlayerLevel : inventory.PlayerLevel, NewLevel: trainingResults.numLevelsGained == 1 ? changedinventory.PlayerLevel : inventory.PlayerLevel,
InventoryChanges: [] InventoryChanges: {}
} satisfies ITrainingResultsResponse); } satisfies ITrainingResultsResponse);
}; };

View File

@ -10,15 +10,17 @@ const addItemController: RequestHandler = async (req, res) => {
const request = toAddItemRequest(req.body); const request = toAddItemRequest(req.body);
switch (request.type) { switch (request.type) {
case ItemType.Powersuit: case ItemType.Powersuit: {
const powersuit = await addPowerSuit(request.InternalName, accountId); const powersuit = await addPowerSuit(request.InternalName, accountId);
res.json(powersuit); res.json(powersuit);
return; return;
case ItemType.Weapon: }
case ItemType.Weapon: {
const weaponType = getWeaponType(request.InternalName); const weaponType = getWeaponType(request.InternalName);
const weapon = await addEquipment(weaponType, request.InternalName, accountId); const weapon = await addEquipment(weaponType, request.InternalName, accountId);
res.json(weapon); res.json(weapon);
break; break;
}
default: default:
res.status(400).json({ error: "something went wrong" }); res.status(400).json({ error: "something went wrong" });
break; break;

View File

@ -6,7 +6,7 @@ import { logger } from "@/src/utils/logger";
const rootDir = path.join(__dirname, "../.."); const rootDir = path.join(__dirname, "../..");
const repoDir = path.basename(rootDir) == "build" ? path.join(rootDir, "..") : rootDir; const repoDir = path.basename(rootDir) == "build" ? path.join(rootDir, "..") : rootDir;
const configPath = path.join(repoDir, "config.json"); const configPath = path.join(repoDir, "config.json");
export const config: IConfig = JSON.parse(fs.readFileSync(configPath, "utf-8")); export const config = JSON.parse(fs.readFileSync(configPath, "utf-8")) as IConfig;
let amnesia = false; let amnesia = false;
fs.watchFile(configPath, () => { fs.watchFile(configPath, () => {

View File

@ -218,7 +218,7 @@ export const addItem = async (
} }
} }
break; break;
case "Weapons": case "Weapons": {
const weaponType = getWeaponType(typeName); const weaponType = getWeaponType(typeName);
const weapon = await addEquipment(weaponType, typeName, accountId); const weapon = await addEquipment(weaponType, typeName, accountId);
await updateSlots(accountId, InventorySlot.WEAPONS, 0, 1); await updateSlots(accountId, InventorySlot.WEAPONS, 0, 1);
@ -228,6 +228,7 @@ export const addItem = async (
[weaponType]: [weapon] [weaponType]: [weapon]
} }
}; };
}
case "Upgrades": { case "Upgrades": {
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const changes = [ const changes = [
@ -263,7 +264,7 @@ export const addItem = async (
} }
case "Types": case "Types":
switch (typeName.substr(1).split("/")[2]) { switch (typeName.substr(1).split("/")[2]) {
case "Sentinels": case "Sentinels": {
// TOOD: Sentinels should also grant their DefaultUpgrades & SentinelWeapon. // TOOD: Sentinels should also grant their DefaultUpgrades & SentinelWeapon.
const sentinel = await addSentinel(typeName, accountId); const sentinel = await addSentinel(typeName, accountId);
await updateSlots(accountId, InventorySlot.SENTINELS, 0, 1); await updateSlots(accountId, InventorySlot.SENTINELS, 0, 1);
@ -273,6 +274,7 @@ export const addItem = async (
Sentinels: [sentinel] Sentinels: [sentinel]
} }
}; };
}
case "Items": { case "Items": {
switch (typeName.substr(1).split("/")[3]) { switch (typeName.substr(1).split("/")[3]) {
case "ShipDecos": { case "ShipDecos": {
@ -328,7 +330,8 @@ export const addItem = async (
}; };
} }
break; break;
case "Restoratives": // Codex Scanner, Remote Observer, Starburst case "Restoratives": {
// Codex Scanner, Remote Observer, Starburst
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const consumablesChanges = [ const consumablesChanges = [
{ {
@ -344,6 +347,7 @@ export const addItem = async (
} }
}; };
} }
}
break; break;
} }
const errorMessage = `unable to add item: ${typeName}`; const errorMessage = `unable to add item: ${typeName}`;

View File

@ -23,8 +23,8 @@ export const getShip = async (shipId: Types.ObjectId, fieldSelection: string = "
const ship = await Ship.findOne({ _id: shipId }, fieldSelection); const ship = await Ship.findOne({ _id: shipId }, fieldSelection);
if (!ship) { if (!ship) {
logger.error(`error finding a ship for account ${shipId}`); logger.error(`error finding a ship for account ${String(shipId)}`);
throw new Error(`error finding a ship for account ${shipId}`); throw new Error(`error finding a ship for account ${String(shipId)}`);
} }
return ship; return ship;