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

40 lines
1.0 KiB
JavaScript
Executable File

const Component = require(`vn-print/core/component`);
const reportBody = new Component('report-body');
const reportFooter = new Component('report-footer');
module.exports = {
name: 'campaign-metrics',
async serverPrefetch() {
this.client = await this.fetchClient(this.id);
this.sales = await this.fetchSales(this.id, this.from, this.to);
if (!this.client)
throw new Error('Something went wrong');
},
methods: {
fetchClient(id) {
return this.findOneFromDef('client', [id]);
},
fetchSales(id, from, to) {
return this.rawSqlFromDef('sales', [id, from, to]);
},
},
components: {
'report-body': reportBody.build(),
'report-footer': reportFooter.build()
},
props: {
id: {
type: Number,
required: true,
description: 'The client id'
},
from: {
required: true
},
to: {
required: true
}
}
};