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