From 8b11a4a2902549e9230311e703f4ed737cbe013e Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 3 May 2024 12:08:22 +0200 Subject: [PATCH 1/3] fix: refs #6005 time issue --- modules/worker/back/models/operator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index 1ebc1643c..d1a30f7db 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -18,7 +18,7 @@ module.exports = Self => { const {backupPrinterNotificationDelay} = await models.ProductionConfig.findOne(); if (backupPrinterNotificationDelay) { const notifications = await models.NotificationQueue.find( - {where: {created: {gte: Date.vnNow() - (backupPrinterNotificationDelay * 1000) + (3600 * 1000)}, + {where: {created: {gte: new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000))}, notificationFk: notificationName, status: 'sent' } -- 2.40.1 From 48bfba71de0cfa8867f89db0a2d5e4c9b20dd2de Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 3 May 2024 12:33:59 +0200 Subject: [PATCH 2/3] fix: refs #6005 runtime --- modules/worker/back/models/operator.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index 1ebc1643c..51995270e 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -30,8 +30,7 @@ module.exports = Self => { return Object.keys(criteria).every(key => criteria[key] === paramsObj?.[key]); }); - if (filteredNotifications.length >= 1) - throw new Error('Previous notification sended with the same parameters'); + if (filteredNotifications.length >= 1) return; } await models.NotificationQueue.create({ -- 2.40.1 From 3ae192c7611130434991179827ff900890454cbc Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 3 May 2024 12:52:12 +0200 Subject: [PATCH 3/3] fix: refs #6005 fix test --- .../methods/operator/spec/operator.spec.js | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/modules/worker/back/methods/operator/spec/operator.spec.js b/modules/worker/back/methods/operator/spec/operator.spec.js index 8a7d05298..c80a6542d 100644 --- a/modules/worker/back/methods/operator/spec/operator.spec.js +++ b/modules/worker/back/methods/operator/spec/operator.spec.js @@ -52,18 +52,16 @@ describe('Operator', () => { }); it('should not sent notification when is already notified by another worker', async() => { - try { - await models.NotificationQueue.create({ - authorFk: 2, - notificationFk: notificationName, - params: JSON.stringify({'labelerId': labeler, 'sectorId': sectorId, 'workerId': 2}), - created: '2001-01-01 12:30:00', - status: sentStatus - }); - await models.Operator.updateAll({id: 1}, {labelerFk: labeler, sectorFk: sectorId}); - } catch (e) { - expect(e.message).toEqual('Previous notification sended with the same parameters'); - } + const {id} = await models.NotificationQueue.create({ + authorFk: 2, + notificationFk: notificationName, + params: JSON.stringify({'labelerId': labeler, 'sectorId': sectorId, 'workerId': 2}), + created: '2001-01-01 11:30:00', + status: sentStatus + }); + const notificationQueue = await updateOperatorAndFindNotification(); + + expect(notificationQueue.id).toEqual(id); }); it('should send a notification when the previous one has distinct params', async() => { -- 2.40.1