refactor: streamline resetGameAchievements with a single try catch

This commit is contained in:
Hachi-R 2025-01-02 06:28:32 -03:00
parent bfdc2787d4
commit 10766526c5

View File

@ -10,6 +10,7 @@ const resetGameAchievements = async (
_event: Electron.IpcMainInvokeEvent, _event: Electron.IpcMainInvokeEvent,
gameId: number gameId: number
) => { ) => {
try {
const game = await gameRepository.findOne({ where: { id: gameId } }); const game = await gameRepository.findOne({ where: { id: gameId } });
if (!game) return; if (!game) return;
@ -17,15 +18,11 @@ const resetGameAchievements = async (
const achievementFiles = findAchievementFiles(game); const achievementFiles = findAchievementFiles(game);
if (achievementFiles.length) { if (achievementFiles.length) {
try {
await Promise.all( await Promise.all(
achievementFiles.map(async (achievementFile) => { achievementFiles.map(async (achievementFile) => {
await fs.promises.rm(achievementFile.filePath, { recursive: true }); await fs.promises.rm(achievementFile.filePath, { recursive: true });
}) })
); );
} catch (error) {
console.error(error);
}
} }
await gameAchievementRepository.update( await gameAchievementRepository.update(
@ -35,11 +32,7 @@ const resetGameAchievements = async (
} }
); );
try {
await HydraApi.delete(`/profile/games/${game.remoteId}/achievements`); await HydraApi.delete(`/profile/games/${game.remoteId}/achievements`);
} catch (error) {
console.error(error);
}
const gameAchievements = await getUnlockedAchievements( const gameAchievements = await getUnlockedAchievements(
game.objectID, game.objectID,
@ -51,6 +44,10 @@ const resetGameAchievements = async (
`on-update-achievements-${game.objectID}-${game.shop}`, `on-update-achievements-${game.objectID}-${game.shop}`,
gameAchievements gameAchievements
); );
} catch (error) {
console.error(error);
}
}; };
registerEvent("resetGameAchievements", resetGameAchievements); registerEvent("resetGameAchievements", resetGameAchievements);