const Component = require(`vn-print/core/component`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); module.exports = { name: 'driver-route', async serverPrefetch() { let ids = this.id; const hasMultipleRoutes = String(this.id).includes(','); if (hasMultipleRoutes) ids = this.id.split(','); const routes = await this.fetchRoutes(ids); const tickets = await this.fetchTickets(ids); 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(ids) { return this.rawSqlFromDef('routes', [ids]); }, fetchTickets(ids) { return this.rawSqlFromDef('tickets', [ids, ids]); } }, components: { 'report-header': reportHeader.build(), 'report-footer': reportFooter.build() }, props: { id: { type: [Number, String], required: true, description: 'The route id' } } };