import { getCities } from './cities' export default class Malls { constructor() { this.currentMall = null this.malls = [] } async init() { const cities = await getCities() this.malls = cities.map(({ name: city, malls }) => malls.map(({ name, code }) => ({ name, code, city }))).reduce((acc, nxt) => acc.concat(nxt), []) this.currentMall = this.malls[0] } async getCurrentMall() { if (!this.malls.length || !this.currentMall) await this.init() return this.currentMall } async getMallByCode(code) { if (!this.malls.length || !this.currentMall) await this.init() this.currentMall = this.malls.find((mall) => mall.code === code) return this.currentMall } setCurrentMall(mall) { this.currentMall = mall } }