mirror of
https://github.com/tcgdex/compiler.git
synced 2025-04-22 10:42:09 +00:00
Added new endpoints: energyTypes trainerTypes suffixes stages dexIds regulationMarks variants
29 lines
969 B
TypeScript
29 lines
969 B
TypeScript
import { CardList, Card as CardSingle } from '@tcgdex/sdk/dist/types/interfaces'
|
|
import { Card, Languages } from '../db/interfaces'
|
|
import { Endpoint } from '../interfaces'
|
|
import { cardToCardSimple, cardToCardSingle, getCards } from '../utils/cardUtil'
|
|
|
|
export default class implements Endpoint<CardList, CardSingle, Record<string, unknown>, Array<[string, Card]>> {
|
|
|
|
public constructor(
|
|
private lang: keyof Languages
|
|
) {}
|
|
|
|
public async index(common: Array<[string, Card]>): Promise<CardList> {
|
|
return Promise.all(common.map((c) => cardToCardSimple(c[0], c[1], this.lang)))
|
|
}
|
|
|
|
public async item(common: Array<[string, Card]>): Promise<Record<string, CardSingle>> {
|
|
const items: Record<string, CardSingle> = {}
|
|
for await (const card of common) {
|
|
items[`${card[1].set.id}-${card[0]}`] = await cardToCardSingle(card[0], card[1], this.lang)
|
|
}
|
|
return items
|
|
}
|
|
|
|
public async common(): Promise<Array<[string, Card]>> {
|
|
return getCards(this.lang)
|
|
}
|
|
|
|
}
|