salix/print/report/rpt-route/index.js

37 lines
1.1 KiB
JavaScript
Executable File

const strftime = require('strftime');
const database = require(`${appPath}/lib/database`);
const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = {
name: 'rpt-route',
async asyncData(ctx, params) {
if (!params.routeFk)
throw new UserException('No route id specified');
let [[route]] = await this.methods.fetchRoute(params.routeFk);
if (!route)
throw new UserException('Route not ready');
return {route};
},
methods: {
fetchRoute(routeFk) {
return database.pool.query(
`SELECT
r.id,
r.time,
am.name agencyName,
v.numberPlate plateNumber
FROM route r
JOIN agencyMode am ON am.id = r.agencyModeFk
JOIN vehicle v ON v.id = r.vehicleFk
WHERE r.id = ?`, [routeFk]);
},
routeTime: routeTime => {
if (routeTime)
return strftime('%H:%M', routeTime);
},
},
};