55 lines
1.6 KiB
JavaScript
Executable File
55 lines
1.6 KiB
JavaScript
Executable File
const UserException = require(`${appPath}/lib/exceptions/userException`);
|
|
const reportEngine = require(`${appPath}/lib/reportEngine`);
|
|
const database = require(`${appPath}/lib/database`);
|
|
const emailHeader = require('../email-header');
|
|
const emailFooter = require('../email-footer');
|
|
|
|
|
|
module.exports = {
|
|
name: 'driver-route',
|
|
async asyncData(ctx, params) {
|
|
const promises = [];
|
|
const data = {
|
|
isPreview: ctx.method === 'GET',
|
|
};
|
|
|
|
if (!params.routeFk)
|
|
throw new UserException('No route id specified');
|
|
|
|
promises.push(reportEngine.toPdf('rpt-route', ctx));
|
|
promises.push(this.methods.fetchRoute(params.routeFk));
|
|
|
|
return Promise.all(promises).then(result => {
|
|
const stream = result[0];
|
|
const [[route]] = result[1];
|
|
|
|
Object.assign(data, route);
|
|
Object.assign(data, {attachments: [{filename: 'driver-route.pdf', content: stream}]});
|
|
|
|
return data;
|
|
});
|
|
},
|
|
created() {
|
|
if (this.locale)
|
|
this.$i18n.locale = this.locale;
|
|
},
|
|
methods: {
|
|
fetchRoute(routeFk) {
|
|
return database.pool.query(`
|
|
SELECT
|
|
u.id,
|
|
u.lang AS locale,
|
|
mu.email AS recipient
|
|
FROM route r
|
|
LEFT JOIN worker w ON w.id = r.workerFk
|
|
LEFT JOIN account.user u ON u.id = w.userFk
|
|
LEFT JOIN account.emailUser mu ON mu.userFk = u.id
|
|
WHERE r.id = ?`, [routeFk]);
|
|
},
|
|
},
|
|
components: {
|
|
emailHeader,
|
|
emailFooter,
|
|
},
|
|
};
|