import Jax from 'App/Services/Jax' import { ChampionDTO, ItemDTO, PerkDTO, PerkStyleDTO, SummonerSpellDTO, } from 'App/Services/Jax/src/Endpoints/CDragonEndpoint' import RoleIdentificationService, { ChampionsPlayRate, } from 'App/Services/RoleIdentificationService' interface Identifiable { id: number } export interface CDragonCache { [id: string]: T } class CDragonService { public champions: CDragonCache public items: CDragonCache public perks: CDragonCache public perkstyles: CDragonCache public summonerSpells: CDragonCache public championRoles: ChampionsPlayRate public readonly BASE_URL = 'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/' private setupCache(dto: T[]) { return dto.reduce((obj, item) => ((obj[item.id] = item), obj), {}) } /** * Get global Context with CDragon Data */ public async getContext() { const items = await Jax.CDragon.items() const champions = await Jax.CDragon.champions() const perks = await Jax.CDragon.perks() const perkstyles = await Jax.CDragon.perkstyles() const summonerSpells = await Jax.CDragon.summonerSpells() const championRoles = await RoleIdentificationService.pullData().catch(() => {}) this.champions = this.setupCache(champions) this.items = this.setupCache(items) this.perks = this.setupCache(perks) this.perkstyles = this.setupCache(perkstyles.styles) this.summonerSpells = this.setupCache(summonerSpells) this.championRoles = championRoles as ChampionsPlayRate } } export default new CDragonService()