const Component = require(`${appPath}/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); module.exports = { name: 'driver-route', async serverPrefetch() { const routesId = this.routeId.split(','); const routes = await this.fetchRoutes(routesId); const tickets = await this.fetchTickets(routesId); const map = new Map(); for (let route of routes) map.set(route.id, route); for (let ticket of tickets) { const route = map.get(ticket.routeFk); if (!route.tickets) route.tickets = []; route.tickets.push(ticket); } this.routes = routes; if (!this.routes) throw new Error('Something went wrong'); }, methods: { fetchRoutes(routesId) { return this.rawSqlFromDef('routes', [routesId]); }, fetchTickets(routesId) { return this.rawSqlFromDef('tickets', [routesId]); } }, components: { 'report-header': reportHeader.build(), 'report-footer': reportFooter.build() }, props: { routeId: { required: true } } };