2019-02-04 09:10:57 +00:00
|
|
|
const database = require(`${appPath}/lib/database`);
|
|
|
|
const reportEngine = require(`${appPath}/lib/reportEngine.js`);
|
|
|
|
const UserException = require(`${appPath}/lib/exceptions/userException`);
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'sepa-core',
|
|
|
|
async asyncData(ctx, params) {
|
|
|
|
const promises = [];
|
|
|
|
const data = {
|
|
|
|
isPreview: ctx.method === 'GET',
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!params.clientFk)
|
|
|
|
throw new UserException('No client id specified');
|
|
|
|
|
|
|
|
promises.push(reportEngine.toPdf('rpt-sepa-core', ctx));
|
|
|
|
promises.push(this.methods.fetchClient(params.clientFk));
|
|
|
|
|
|
|
|
return Promise.all(promises).then(result => {
|
|
|
|
const stream = result[0];
|
|
|
|
const [[client]] = result[1];
|
|
|
|
|
|
|
|
Object.assign(data, client);
|
|
|
|
Object.assign(data, {attachments: [{filename: 'rpt-sepa-core.pdf', content: stream}]});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
created() {
|
2019-02-05 06:58:05 +00:00
|
|
|
if (this.locale)
|
|
|
|
this.$i18n.locale = this.locale;
|
2019-02-04 09:10:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
fetchClient(clientFk) {
|
|
|
|
return database.pool.query(`
|
|
|
|
SELECT
|
|
|
|
u.lang locale,
|
|
|
|
c.email recipient
|
|
|
|
FROM client c
|
|
|
|
JOIN account.user u ON u.id = c.id
|
|
|
|
WHERE c.id = ?`, [clientFk]);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
'email-header': require('../email-header'),
|
|
|
|
'email-footer': require('../email-footer'),
|
|
|
|
},
|
|
|
|
};
|