import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces' import { Card, Languages } from '../db/interfaces' import { Endpoint } from '../interfaces' import { cardToCardSimple, getCards } from '../utils/cardUtil' export default class implements Endpoint, Record>> { public constructor( private lang: keyof Languages ) {} public async index(common: Record>): Promise { return Object.keys(common) } public async item(common: Record>): Promise> { const items: Record = {} for await (const key of Object.keys(common)) { const val = common[key] items[key] = { cards: await Promise.all(val.map(([id, card]) => cardToCardSimple(id, card, this.lang))), name: key } } return items } public async common(): Promise>> { return (await getCards(this.lang)).reduce((p, c) => { const { trainerType } = c[1] if (!trainerType) { return p } if (!p[trainerType]) { p[trainerType] = [] } p[trainerType].push(c) return p }, {} as Record>) } }