refactor(printer-notification): refs #6005 refactor de la notificación

This commit is contained in:
Pablo Natek 2023-11-09 07:56:35 +01:00
parent 779ca2cc05
commit 9c896c835f
17 changed files with 62 additions and 35 deletions

View File

@ -0,0 +1,19 @@
ALTER TABLE `vn`.`sector` CHANGE `mainPrinterFk` `backupPrinterFk` tinyint(3) unsigned DEFAULT NULL NULL;
ALTER TABLE `util`.`notificationSubscription` DROP FOREIGN KEY `notificationSubscription_ibfk_1`;
ALTER TABLE `util`.`notificationQueue` DROP FOREIGN KEY `nnotificationQueue_ibfk_1`;
ALTER TABLE `util`.`notificationAcl` DROP FOREIGN KEY `notificationAcl_ibfk_1`;
ALTER TABLE `util`.`notification` MODIFY COLUMN `id` int(11) auto_increment NOT NULL;
ALTER TABLE `util`.`notificationSubscription` ADD CONSTRAINT `notificationSubscription_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`id`);
ALTER TABLE `util`.`notificationQueue` ADD CONSTRAINT `notificationQueue_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`name`);
ALTER TABLE `util`.`notificationAcl` ADD CONSTRAINT `notificationAcl_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`id`);
DELETE FROM `util`.`notification`
WHERE `name` = 'not-main-printer-configured';
INSERT INTO `util`.`notification`
SET `id` = 15,
`name` = 'backup-printer-selected',
`description` = 'The worker has selected the backup printer for their sector';

View File

@ -174,19 +174,16 @@ INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory
(13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 2, 1, 0),
(60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0);
INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`)
VALUES
(1, 'First sector', 1, 1, 'FIRST'),
(2, 'Second sector', 2, 0, 'SECOND');
INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAddress`)
VALUES
(1, 'printer1', 'path1', 0, 1 , NULL),
(2, 'printer2', 'path2', 1, 1 , NULL),
(4, 'printer4', 'path4', 0, NULL, '10.1.10.4');
UPDATE `vn`.`sector` SET mainPrinterFk = 1 WHERE id = 1;
INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`, `backupPrinterFk`)
VALUES
(1, 'First sector', 1, 1, 'FIRST', 1),
(2, 'Second sector', 2, 0, 'SECOND', NULL);
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`,`bossFk`, `phone`)
VALUES
@ -2780,11 +2777,13 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`)
VALUES
(1, 'print-email', 'notification fixture one'),
(2, 'invoice-electronic', 'A electronic invoice has been generated'),
(3, 'not-main-printer-configured', 'A printer distinct than main has been configured'),
(4, 'supplier-pay-method-update', 'A supplier pay method has been updated'),
(5, 'modified-entry', 'An entry has been modified'),
(6, 'book-entry-deleted', 'accounting entries deleted');
INSERT IGNORE INTO `util`.`notification` (`id`, `name`, `description`)
VALUES (3, 'backup-printer-selected', 'A printer distinct than main has been configured');
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
VALUES
(1, 9),

View File

@ -56,7 +56,7 @@
"type": "number",
"required": false
},
"mainPrinterFk": {
"backupPrinterFk": {
"type": "number",
"required": false
},

View File

@ -4,7 +4,7 @@ describe('Operator', () => {
const authorFk = 9;
const sectorId = 1;
const mainPrinter = 1;
const notificationName = 'not-main-printer-configured';
const notificationName = 'backup-printer-selected';
const operator = {
workerFk: 1,
trainFk: 1,

View File

@ -1,5 +1,5 @@
module.exports = function(Self) {
Self.observe('after save', async function(ctx) {
Self.observe('after save', async ctx => {
const instance = ctx.data || ctx.instance;
const models = Self.app.models;
const options = ctx.options;
@ -7,13 +7,13 @@ module.exports = function(Self) {
if (!instance?.sectorFk || !instance?.labelerFk) return;
const sector = await models.Sector.findById(instance.sectorFk, {
fields: ['mainPrinterFk']
fields: ['backupPrinterFk']
}, options);
if (sector.mainPrinterFk && sector.mainPrinterFk != instance.labelerFk) {
const userId = ctx.options.accessToken.userId;
if (sector.backupPrinterFk && sector.backupPrinterFk == instance.labelerFk) {
const {userId} = ctx.options.accessToken;
await models.NotificationQueue.create({
notificationFk: 'not-main-printer-configured',
notificationFk: 'backup-printer-selected',
authorFk: userId,
params: JSON.stringify(
{

View File

@ -0,0 +1,14 @@
<email-body v-bind="$props">
<div class="grid-row">
<div class="grid-block vn-pa-ml">
<h1>{{ $t('title') }}</h1>
<p v-html="$t('description',
[
worker.nickname,
labeler.id,
sector.description,
]
)"/>
</div>
</div>
</email-body>

View File

@ -2,7 +2,7 @@ const Component = require(`vn-print/core/component`);
const emailBody = new Component('email-body');
module.exports = {
name: 'not-main-printer-configured',
name: 'backup-printer-selected',
async serverPrefetch() {
this.sector = await this.findOneFromDef('sector', [this.sectorId]);
@ -10,7 +10,7 @@ module.exports = {
throw new Error('Something went wrong');
this.labeler = await this.findOneFromDef('printer', [this.labelerId]);
this.mainPrinter = await this.findOneFromDef('printer', [this.sector.mainPrinterFk]);
this.mainPrinter = await this.findOneFromDef('printer', [this.sector.backupPrinterFk]);
this.worker = await this.findOneFromDef('worker', [this.workerId]);
},
components: {

View File

@ -0,0 +1,3 @@
subject: Not main printer configured
title: Not main printer configured
description: 'The worker #{0} is using the backup printer {1} for their sector {2}.'

View File

@ -0,0 +1,3 @@
subject: Configurada impresora no principal
title: Configurada impresora no principal
description: 'El trabajador #{0} esta utilizando la impresora de repuesto {1} su sector {2}.'

View File

@ -1,3 +1,4 @@
SELECT id, name
SELECT id,
name
FROM vn.printer
WHERE id = ?

View File

@ -0,0 +1,5 @@
SELECT id,
description,
backupPrinterFk
FROM vn.sector
WHERE id = ?

View File

@ -1,3 +0,0 @@
subject: Not main printer configured
title: Not main printer configured
description: 'Printer #{0} {1} has been configured in sector #{2} {3} (the main printer for that sector is #{4} {5}). Ask the worker {6}.'

View File

@ -1,3 +0,0 @@
subject: Configurada impresora no principal
title: Configurada impresora no principal
description: 'Se ha configurado la impresora #{0} {1} en el sector #{2} {3} (la impresora principal de ese sector es la #{4} {5}). Preguntar al trabajador {6}.'

View File

@ -1,8 +0,0 @@
<email-body v-bind="$props">
<div class="grid-row">
<div class="grid-block vn-pa-ml">
<h1>{{ $t('title') }}</h1>
<p v-html="$t('description', [labeler.id, labeler.name, sector.id, sector.description, mainPrinter.id, mainPrinter.name, worker.nickname])"></p>
</div>
</div>
</email-body>

View File

@ -1,3 +0,0 @@
SELECT id, description, mainPrinterFk
FROM vn.sector
WHERE id = ?