Skip to content

Commit

Permalink
🐛 Handle the "Mystery Game" from Epic Games use case
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonypillot committed May 13, 2023
1 parent 6930bdd commit 63c4001
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/helpers/epic.games.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export class EpicGamesMapper {
const newElementsToSave: GameInterface[] = data.map((game) => {
const newElement: GameInterface = {
title: game.title,
description: game.description,
urlSlug: `https://store.epicgames.com/fr/p/${
game.productSlug || game.catalogNs.mappings[0]?.pageSlug
}`,
description:
game.description === "Mystery Game"
? "Jeu mystère ! Celui-ci ne sera révélé que le jour de sa sortie. Rendez-vous le jour J pour le découvrir !"
: game.description,
urlSlug: constructUrl(game),
promotion: {
startDate: game.free
? game.promotions.promotionalOffers[0].promotionalOffers[0].startDate.toString()
Expand All @@ -34,3 +35,18 @@ export class EpicGamesMapper {
}
}
}

function constructUrl(game: Element): string {
const productGamePage = "https://store.epicgames.com/fr/p";
const freeGamePage = "https://store.epicgames.com/fr/free-games";

// sometimes, productSlug is an empty array, so we need to check it,
// in the case of a "Mystery Game", for example
if (game.productSlug && game.productSlug != "[]") {
return `${productGamePage}/${game.productSlug}`;
} else if (game.catalogNs.mappings[0]?.pageSlug) {
return `${productGamePage}/${game.catalogNs.mappings[0]?.pageSlug}`;
} else {
return freeGamePage;
}
}

0 comments on commit 63c4001

Please sign in to comment.