refactor: refs #6005 move the logic to the report
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
ab7eb88913
commit
1c40e01fcb
|
@ -1,29 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.observe('before save', async ctx => {
|
||||
const instance = ctx.data || ctx.instance;
|
||||
const {notificationFk} = instance;
|
||||
|
||||
if (!(notificationFk === 'backup-printer-selected')) return;
|
||||
const {models} = Self.app;
|
||||
const params = JSON.parse(instance.params);
|
||||
const options = ctx.options;
|
||||
const {delay} = await models.Notification.findOne({
|
||||
where: {name: notificationFk}
|
||||
}, options);
|
||||
|
||||
const hasNotified = await models.NotificationQueue.findOne({
|
||||
where: {
|
||||
notificationFk: notificationFk,
|
||||
and: [
|
||||
{params: {like: '%\"labelerId\":' + params.labelerId + '%'}},
|
||||
{params: {like: '%\"sectorId\":' + params.sectorId + '%'}}
|
||||
]
|
||||
},
|
||||
order: 'created DESC',
|
||||
}, options);
|
||||
|
||||
if (hasNotified?.created - Date.now() > delay || !hasNotified?.created || !delay) return;
|
||||
|
||||
throw new Error('Is already Notified');
|
||||
});
|
||||
};
|
|
@ -113,9 +113,6 @@ INSERT INTO vn.ticket (clientFk, warehouseFk, shipped, nickname, refFk, addressF
|
|||
(100, 4, '2022-07-12 00:00:00', 'root', NULL, 195, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-12 16:18:58', 1, NULL, 4, NULL, 1, 567, 1, '2022-07-12', 0, 0, 6, NULL, NULL, NULL, NULL, NULL),
|
||||
(100, 5, '2022-07-12 00:00:00', 'root', NULL, 195, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-12 16:18:58', 1, NULL, 5, NULL, 1, 567, 1, '2022-07-12', 0, 0, 1, NULL, NULL, NULL, NULL, NULL);
|
||||
*/
|
||||
INSERT INTO vn.sector (description,warehouseFk) VALUES
|
||||
('Sector One',1);
|
||||
|
||||
INSERT INTO vn.saleGroup (userFk,parkingFk,sectorFk) VALUES
|
||||
(100,1,1);
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAd
|
|||
(2, 'printer2', 'path2', 1, 1 , NULL),
|
||||
(4, 'printer4', 'path4', 0, NULL, '10.1.10.4');
|
||||
|
||||
UPDATE `vn`.`sector` SET mainPrinterFk = 1 WHERE id = 1;
|
||||
UPDATE `vn`.`sector` SET `backupPrinterFk` = 1 WHERE id = 1;
|
||||
|
||||
|
||||
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`,`bossFk`, `phone`)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
ALTER TABLE `vn`.`packingSite` DROP FOREIGN KEY IF EXISTS `packingSite_FK_4`;
|
||||
ALTER TABLE `vn`.`arcRead` DROP FOREIGN KEY IF EXISTS `worker_printer_FK`;
|
||||
ALTER TABLE `vn`.`host` DROP FOREIGN KEY IF EXISTS `configHost_FK`;
|
||||
ALTER TABLE `vn`.`operator` DROP FOREIGN KEY IF EXISTS `operator_FK_5`;
|
||||
ALTER TABLE `vn`.`packingSite` DROP FOREIGN KEY IF EXISTS `packingSite_FK_1`;
|
||||
ALTER TABLE `vn`.`printQueue` DROP FOREIGN KEY IF EXISTS `printQueue_printerFk`;
|
||||
ALTER TABLE `vn`.`sector` DROP FOREIGN KEY IF EXISTS `sector_FK_1`;
|
||||
ALTER TABLE `vn`.`worker` DROP FOREIGN KEY IF EXISTS `worker_FK`;
|
||||
ALTER TABLE dipole.printer DROP FOREIGN KEY IF EXISTS printer_FK;
|
||||
ALTER TABLE dipole.expedition_PrintOut DROP FOREIGN KEY IF EXISTS expedition_PrintOut_FK;
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
ALTER TABLE `vn`.`printer` MODIFY COLUMN IF EXISTS `id` int unsigned auto_increment NOT NULL;
|
||||
|
||||
ALTER TABLE `vn`.`arcRead` MODIFY COLUMN IF EXISTS `printerFk` int unsigned DEFAULT NULL NULL;
|
||||
ALTER TABLE `vn`.`arcRead` ADD CONSTRAINT `arcRead_FK` FOREIGN KEY IF NOT EXISTS (printerFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `vn`.`host` MODIFY COLUMN IF EXISTS `printerFk` int unsigned DEFAULT NULL NULL;
|
||||
ALTER TABLE `vn`.`host` ADD CONSTRAINT `host_FK` FOREIGN KEY IF NOT EXISTS (printerFk) REFERENCES vn.printer(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `vn`.`operator` MODIFY COLUMN IF EXISTS `labelerFk` int unsigned DEFAULT NULL NULL;
|
||||
ALTER TABLE `vn`.`operator` ADD CONSTRAINT `operator_FK_4` FOREIGN KEY IF NOT EXISTS (labelerFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `vn`.`packingSite` MODIFY COLUMN IF EXISTS `printerFk` int unsigned DEFAULT NULL NULL;
|
||||
ALTER TABLE `vn`.`packingSite` ADD CONSTRAINT `packingSite_FK_1` FOREIGN KEY IF NOT EXISTS (printerFk) REFERENCES vn.printer(id) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
||||
|
||||
ALTER TABLE `vn`.`packingSite` MODIFY COLUMN IF EXISTS `printerRfidFk` int unsigned DEFAULT NULL NULL;
|
||||
ALTER TABLE `vn`.`packingSite` ADD CONSTRAINT `packingSite_FK_4` FOREIGN KEY IF NOT EXISTS(printerRfidFk) REFERENCES vn.printer(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `vn`.`printQueue` MODIFY COLUMN IF EXISTS `printerFk` int unsigned DEFAULT NULL NULL;
|
||||
ALTER TABLE `vn`.`printQueue` ADD CONSTRAINT `printQueue_FK` FOREIGN KEY IF NOT EXISTS (id) REFERENCES vn.printer(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `vn`.`sector` MODIFY COLUMN IF EXISTS `mainPrinterFk` int unsigned DEFAULT NULL NULL;
|
||||
ALTER TABLE `vn`.`sector` ADD CONSTRAINT `sector_FK` FOREIGN KEY IF NOT EXISTS (mainPrinterFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `dipole`.`printer` MODIFY COLUMN IF EXISTS `id` int unsigned DEFAULT NULL NULL;
|
||||
ALTER TABLE `dipole`.`printer` ADD CONSTRAINT `vnPrinter_FK` FOREIGN KEY IF NOT EXISTS (id) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `dipole`.`expedition_PrintOut` MODIFY COLUMN IF EXISTS `printerFk` int unsigned DEFAULT 0 NOT NULL;
|
||||
ALTER TABLE `dipole`.`expedition_PrintOut` ADD CONSTRAINT `expedition_PrintOut_FK` FOREIGN KEY IF NOT EXISTS (printerFk) REFERENCES printer(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
ALTER TABLE `util`.`notification` ADD IF NOT EXISTS delay int unsigned NULL
|
||||
COMMENT 'Minimum seconds Interval to Prevent Spam from Same-Type Notifications';
|
||||
|
||||
ALTER TABLE vn.sector DROP FOREIGN KEY IF EXISTS sector_FK;
|
||||
|
||||
ALTER TABLE `vn`.`sector` CHANGE IF EXISTS `mainPrinterFk` `backupPrinterFk` int unsigned DEFAULT NULL NULL;
|
||||
|
||||
ALTER TABLE `util`.`notificationSubscription` DROP FOREIGN KEY IF EXISTS `notificationSubscription_ibfk_1`;
|
||||
ALTER TABLE `util`.`notificationQueue` DROP FOREIGN KEY IF EXISTS `nnotificationQueue_ibfk_1`;
|
||||
ALTER TABLE `util`.`notificationAcl` DROP FOREIGN KEY IF EXISTS `notificationAcl_ibfk_1`;
|
||||
|
||||
ALTER TABLE `util`.`notification` MODIFY COLUMN IF EXISTS `id` int(11) auto_increment NOT NULL;
|
||||
|
||||
ALTER TABLE `util`.`notificationSubscription` ADD CONSTRAINT `notificationSubscription_Fk` FOREIGN KEY IF NOT EXISTS (`notificationFk`) REFERENCES `util`.`notification`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE `util`.`notificationQueue` ADD CONSTRAINT `notificationQueue_Fk` FOREIGN KEY IF NOT EXISTS (`notificationFk`) REFERENCES `util`.`notification`(`name`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE `util`.`notificationAcl` ADD CONSTRAINT `notificationAcl_Fk` FOREIGN KEY IF NOT EXISTS (`notificationFk`) REFERENCES `util`.`notification`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1,12 @@
|
|||
INSERT IGNORE INTO util.notification (name, description, delay)
|
||||
VALUES ('backup-printer-selected','A backup printer has been selected', 3600);
|
||||
|
||||
INSERT IGNORE INTO util.notificationSubscription (notificationFk, userFk)
|
||||
SELECT id, 10435
|
||||
FROM util.notification
|
||||
WHERE name = 'backup-printer-selected';
|
||||
|
||||
INSERT IGNORE INTO util.notificationAcl (notificationFk, roleFk)
|
||||
SELECT id, 66
|
||||
FROM util.notification
|
||||
WHERE name = 'backup-printer-selected';
|
|
@ -1,11 +1,15 @@
|
|||
const Component = require(`vn-print/core/component`);
|
||||
const emailBody = new Component('email-body');
|
||||
const name = 'backup-printer-selected';
|
||||
|
||||
module.exports = {
|
||||
name: 'backup-printer-selected',
|
||||
name: name,
|
||||
async serverPrefetch() {
|
||||
this.sector = await this.findOneFromDef('sector', [this.sectorId]);
|
||||
const notifications = await this.rawSqlFromDef('previousNotifications', [name]);
|
||||
if (notifications && checkDuplicates(notifications, this.labelerId, this.sectorId))
|
||||
throw new Error('Previous notification sended with the same parameters');
|
||||
|
||||
this.sector = await this.findOneFromDef('sector', [this.sectorId]);
|
||||
if (!this.sector)
|
||||
throw new Error('Something went wrong');
|
||||
|
||||
|
@ -31,3 +35,16 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
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]);
|
||||
});
|
||||
|
||||
return filteredNotifications.size > 1;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
SELECT nq.params
|
||||
FROM util.notificationQueue nq
|
||||
JOIN util.notification n ON n.name = nq.notificationFk
|
||||
WHERE n.name = ?
|
||||
AND TIMESTAMPDIFF(SECOND, nq.created, util.VN_NOW()) <= n.delay
|
Loading…
Reference in New Issue