mirror of
https://github.com/tcgdex/compiler.git
synced 2025-04-22 02:32:10 +00:00
* Done ! Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net> * ACT doesn't wanna work so I push Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net> * Continued work on ESLint Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net> * Two files remaining Signed-off-by: Avior <github@avior.me> * Fixed set cards not found when using ids Signed-off-by: Avior <florian.bouillon@delta-wings.net>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { SetList, Set as SetSingle, Card as CardSingle } from '@tcgdex/sdk/interfaces'
|
|
import { getSets, isSetAvailable, setToSetSimple, setToSetSingle } from '../utils/setUtil'
|
|
import { Languages, Set } from '../db/interfaces'
|
|
import { Endpoint } from '../interfaces'
|
|
import { cardToCardSingle, getCards } from '../utils/cardUtil'
|
|
|
|
export default class implements Endpoint<SetList, SetSingle, CardSingle, Array<Set>> {
|
|
|
|
public constructor(
|
|
private lang: keyof Languages
|
|
) {}
|
|
|
|
public async index(common: Array<Set>): Promise<SetList> {
|
|
const sets = common
|
|
.sort((a, b) => a.releaseDate > b.releaseDate ? 1 : -1)
|
|
|
|
const tmp: SetList = await Promise.all(sets.map((el) => setToSetSimple(el, this.lang)))
|
|
|
|
return tmp
|
|
}
|
|
|
|
public async item(common: Array<Set>): Promise<Record<string, SetSingle>> {
|
|
const sets = await Promise.all(common
|
|
.map((set) => setToSetSingle(set, this.lang)))
|
|
const res: Record<string, SetSingle> = {}
|
|
|
|
for (const set of sets) {
|
|
res[set.name] = set
|
|
res[set.id] = set
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
public async common(): Promise<Array<Set>> {
|
|
return getSets(undefined, this.lang)
|
|
}
|
|
|
|
public async sub(common: Array<Set>, item: string): Promise<Record<string, CardSingle> | undefined> {
|
|
const set = common.find((s) => s.name[this.lang] === item || s.id === item)
|
|
|
|
if (!set || !isSetAvailable(set, this.lang)) {
|
|
return undefined
|
|
}
|
|
|
|
const lit = await getCards(this.lang, set)
|
|
const list: Record<string, CardSingle> = {}
|
|
for await (const card of lit) {
|
|
list[card[0]] = await cardToCardSingle(card[0], card[1], this.lang)
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
}
|