Automatically calculate the set.cardCount.total field (#11)

Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2021-06-18 21:10:05 +02:00 committed by GitHub
parent 19c6674d30
commit 4116c1f6be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,6 +65,7 @@ export async function getSetPictures(set: Set, lang: SupportedLanguages): Promis
}
export async function setToSetSimple(set: Set, lang: SupportedLanguages): Promise<SetResume> {
const cards = await getCards(lang, set)
const pics = await getSetPictures(set, lang)
return {
id: set.id,
@ -72,7 +73,7 @@ export async function setToSetSimple(set: Set, lang: SupportedLanguages): Promis
symbol: pics[1],
name: set.name[lang] as string,
cardCount: {
total: set.cardCount.total,
total: Math.max(set.cardCount.official, cards.length),
official: set.cardCount.official
},
}
@ -90,7 +91,7 @@ export async function setToSetSingle(set: Set, lang: SupportedLanguages): Promis
},
tcgOnline: set.tcgOnline,
cardCount: {
total: set.cardCount.total,
total: Math.max(set.cardCount.official, cards.length),
official: set.cardCount.official,
normal: cards.reduce((count, card) => count + (card[1].variants?.normal ?? set.variants?.normal ? 1 : 0), 0),
reverse: cards.reduce((count, card) => count + (card[1].variants?.reverse ?? set.variants?.reverse ? 1 : 0), 0),