feat: refactor

This commit is contained in:
Zamitto 2024-09-12 11:35:14 -03:00
parent 2e82c29f4c
commit b8c8e534b4

View File

@ -1,7 +1,7 @@
import { registerEvent } from "../register-event"; import { registerEvent } from "../register-event";
import { getSteamGameById } from "../helpers/search-games"; import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
import { CatalogueEntry } from "@types"; import { CatalogueEntry } from "@types";
import { HydraApi } from "@main/services"; import { HydraApi, RepacksManager } from "@main/services";
const searchGamesEvent = async ( const searchGamesEvent = async (
_event: Electron.IpcMainInvokeEvent, _event: Electron.IpcMainInvokeEvent,
@ -11,14 +11,15 @@ const searchGamesEvent = async (
{ objectId: string; title: string; shop: string }[] { objectId: string; title: string; shop: string }[]
>("/games/search", { title: query, take: 12, skip: 0 }, { needsAuth: false }); >("/games/search", { title: query, take: 12, skip: 0 }, { needsAuth: false });
const steamGames = await Promise.all( const steamGames = games.map((game) => {
games.map((game) => getSteamGameById(game.objectId)) return convertSteamGameToCatalogueEntry({
); id: Number(game.objectId),
const filteredGames = steamGames.filter( name: game.title,
(game) => game !== null clientIcon: null,
) as CatalogueEntry[]; });
});
return filteredGames; return RepacksManager.findRepacksForCatalogueEntries(steamGames);
}; };
registerEvent("searchGames", searchGamesEvent); registerEvent("searchGames", searchGamesEvent);