2023-05-10 11:22:53 +00:00
|
|
|
const Component = require(`vn-print/core/component`);
|
|
|
|
const emailBody = new Component('email-body');
|
2024-02-20 12:49:42 +00:00
|
|
|
const name = 'backup-printer-selected';
|
2023-05-10 11:22:53 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2024-02-20 12:49:42 +00:00
|
|
|
name: name,
|
2023-05-29 10:55:20 +00:00
|
|
|
async serverPrefetch() {
|
2024-02-20 12:49:42 +00:00
|
|
|
const notifications = await this.rawSqlFromDef('previousNotifications', [name]);
|
2024-03-06 13:51:34 +00:00
|
|
|
if (!notifications.length || checkDuplicates(notifications, this.labelerId, this.sectorId))
|
2024-02-20 12:49:42 +00:00
|
|
|
throw new Error('Previous notification sended with the same parameters');
|
2023-05-29 10:55:20 +00:00
|
|
|
|
2024-02-20 12:49:42 +00:00
|
|
|
this.sector = await this.findOneFromDef('sector', [this.sectorId]);
|
2023-05-29 10:55:20 +00:00
|
|
|
if (!this.sector)
|
|
|
|
throw new Error('Something went wrong');
|
|
|
|
|
|
|
|
this.labeler = await this.findOneFromDef('printer', [this.labelerId]);
|
2023-11-09 06:56:35 +00:00
|
|
|
this.mainPrinter = await this.findOneFromDef('printer', [this.sector.backupPrinterFk]);
|
2023-05-29 10:55:20 +00:00
|
|
|
this.worker = await this.findOneFromDef('worker', [this.workerId]);
|
|
|
|
},
|
2023-05-10 11:22:53 +00:00
|
|
|
components: {
|
|
|
|
'email-body': emailBody.build(),
|
|
|
|
},
|
|
|
|
props: {
|
2023-05-29 10:55:20 +00:00
|
|
|
labelerId: {
|
|
|
|
type: Number,
|
2023-05-10 11:22:53 +00:00
|
|
|
required: true
|
|
|
|
},
|
2023-05-29 10:55:20 +00:00
|
|
|
sectorId: {
|
|
|
|
type: Number,
|
2023-05-10 11:22:53 +00:00
|
|
|
required: true
|
|
|
|
},
|
2023-05-29 10:55:20 +00:00
|
|
|
workerId: {
|
|
|
|
type: Number,
|
2023-05-10 11:22:53 +00:00
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2024-02-20 12:49:42 +00:00
|
|
|
|
|
|
|
function checkDuplicates(notifications, labelerFk, printerFk) {
|
|
|
|
const criteria = {
|
|
|
|
labelerId: labelerFk,
|
|
|
|
sectorId: printerFk
|
|
|
|
};
|
|
|
|
const filteredNotifications = notifications.filter(notification => {
|
|
|
|
const paramsObj = JSON.parse(notification.params);
|
|
|
|
return Object.keys(criteria).every(key => criteria[key] === paramsObj[key]);
|
|
|
|
});
|
2024-02-21 11:59:42 +00:00
|
|
|
return filteredNotifications.length > 1;
|
2024-02-20 12:49:42 +00:00
|
|
|
}
|