salix/print/templates/reports/campaign-metrics/campaign-metrics.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-11-27 15:00:42 +00:00
const Component = require(`${appPath}/core/component`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
module.exports = {
name: 'campaign-metrics',
async serverPrefetch() {
2020-05-22 13:20:55 +00:00
this.client = await this.fetchClient(this.recipientId);
this.sales = await this.fetchSales(this.recipientId, this.from, this.to);
2019-11-27 15:00:42 +00:00
if (!this.client)
throw new Error('Something went wrong');
},
methods: {
fetchClient(clientId) {
2020-09-28 11:54:02 +00:00
return this.findOneFromDef('client', [clientId]);
2019-11-27 15:00:42 +00:00
},
fetchSales(clientId, from, to) {
2020-09-28 11:54:02 +00:00
return this.rawSqlFromDef('sales', [clientId, from, to]);
2019-11-27 15:00:42 +00:00
},
},
components: {
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
},
props: {
2020-05-22 13:20:55 +00:00
recipientId: {
2019-11-27 15:00:42 +00:00
required: true
},
from: {
2020-06-12 07:18:19 +00:00
required: true
2019-11-27 15:00:42 +00:00
},
to: {
2020-06-12 07:18:19 +00:00
required: true
2019-11-27 15:00:42 +00:00
}
}
};