salix/print/templates/email/osticket-report/osticket-report.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-09-27 12:20:57 +00:00
const Component = require(`vn-print/core/component`);
2022-11-10 08:51:28 +00:00
const emailBody = new Component('email-body');
2021-04-27 08:29:09 +00:00
module.exports = {
name: 'osticket-report',
async serverPrefetch() {
const tickets = await this.fetchTickets();
this.resolvedTickets = tickets.length;
const technicians = [];
for (let ticket of tickets) {
const technicianName = ticket.assigned;
let technician = technicians.find(technician => {
return technician.name == technicianName;
});
if (!technician) {
technician = {
name: technicianName,
tickets: []
};
technicians.push(technician);
}
technician.tickets.push(ticket);
}
this.technicians = technicians.sort((acumulator, value) => {
return value.tickets.length - acumulator.tickets.length;
});
if (!this.technicians)
throw new Error('Something went wrong');
},
computed: {
dated: function() {
const filters = this.$options.filters;
2023-01-16 14:18:24 +00:00
return filters.date(Date.vnNew(), '%d-%m-%Y');
2021-04-27 08:29:09 +00:00
},
startedTime: function() {
return new Date(this.started).getTime();
},
endedTime: function() {
return new Date(this.ended).getTime();
}
},
methods: {
fetchDateRange() {
return this.findOneFromDef('dateRange');
},
async fetchTickets() {
const {started, ended} = await this.fetchDateRange();
this.started = started;
this.ended = ended;
const connection = await this.getConnection('osticket');
return this.rawSqlFromDef('tickets', [started, ended], connection);
}
},
components: {
2022-11-10 08:51:28 +00:00
'email-body': emailBody.build(),
2021-04-27 08:29:09 +00:00
},
props: {}
};