refactor: refs #6005 delay on productionConfig
This commit is contained in:
parent
7cb40f5d89
commit
da037c5235
|
@ -174,5 +174,8 @@
|
|||
},
|
||||
"WorkerActivityType": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ProductionConfig": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "ProductionConfig",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "productionConfig"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"id": true
|
||||
},
|
||||
"backupPrinterNotificationDelay": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -153,16 +153,6 @@ INSERT INTO `vn`.`occupationCode` (`code`, `name`)
|
|||
('b', 'Representantes de comercio'),
|
||||
('c', 'Personal de oficios en trabajos de construcción en general, y en instalac.,edificios y obras');
|
||||
|
||||
INSERT INTO `vn2008`.`payroll_employee` (`CodTrabajador`,`codempresa`)
|
||||
VALUES
|
||||
(36,20),
|
||||
(43,20),
|
||||
(76,20),
|
||||
(1106,20),
|
||||
(1107,20),
|
||||
(1108,20),
|
||||
(1109,20),
|
||||
(1110,20);
|
||||
|
||||
INSERT INTO `vn`.`trainingCourseType` (`id`, `name`)
|
||||
VALUES
|
||||
|
|
|
@ -2805,16 +2805,16 @@ INSERT INTO `util`.`notificationConfig`
|
|||
SET `id` = 1,
|
||||
`cleanDays` = 90;
|
||||
TRUNCATE `util`.`notification`;
|
||||
INSERT INTO `util`.`notification` (`id`, `name`, `description`, `delay`)
|
||||
INSERT INTO `util`.`notification` (`id`, `name`, `description`)
|
||||
VALUES
|
||||
(1, 'print-email', 'notification fixture one', NULL),
|
||||
(2, 'invoice-electronic', 'A electronic invoice has been generated', NULL),
|
||||
(3, 'not-main-printer-configured', 'A printer distinct than main has been configured', NULL),
|
||||
(4, 'supplier-pay-method-update', 'A supplier pay method has been updated', NULL),
|
||||
(5, 'modified-entry', 'An entry has been modified', NULL),
|
||||
(6, 'book-entry-deleted', 'accounting entries deleted', NULL),
|
||||
(7, 'zone-included','An email to notify zoneCollisions');
|
||||
(8, 'backup-printer-selected','A backup printer has been selected', 3600),
|
||||
(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'),
|
||||
(7, 'zone-included','An email to notify zoneCollisions'),
|
||||
(8, 'backup-printer-selected','A backup printer has been selected');
|
||||
|
||||
TRUNCATE `util`.`notificationAcl`;
|
||||
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
|
||||
|
@ -2854,9 +2854,9 @@ INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
|
|||
VALUES
|
||||
(1, 9);
|
||||
|
||||
INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`)
|
||||
INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`, `backupPrinterNotificationDelay`)
|
||||
VALUES
|
||||
(0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6);
|
||||
(0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6, 3600);
|
||||
|
||||
INSERT INTO `vn`.`collection` (`id`, `created`, `workerFk`, `stateFk`, `itemPackingTypeFk`, `saleTotalCount`, `salePickedCount`, `trainFk`, `sectorFk`, `wagons`)
|
||||
VALUES
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
ALTER TABLE `util`.`notification` ADD IF NOT EXISTS delay int unsigned NULL
|
||||
ALTER TABLE `vn`.`productionConfig` ADD IF NOT EXISTS backupPrinterNotificationDelay 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;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
INSERT IGNORE INTO util.notification (name, description, delay)
|
||||
VALUES ('backup-printer-selected','A backup printer has been selected', 3600);
|
||||
INSERT IGNORE INTO util.notification (name, description)
|
||||
VALUES ('backup-printer-selected','A backup printer has been selected');
|
||||
|
||||
INSERT IGNORE INTO util.notificationSubscription (notificationFk, userFk)
|
||||
SELECT id, 10435
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Operator', () => {
|
||||
fdescribe('Operator', () => {
|
||||
const authorFk = 9;
|
||||
const sectorId = 1;
|
||||
const labeler = 1;
|
||||
const notificationName = 'backup-printer-selected';
|
||||
const errorStatus = 'error';
|
||||
const sentStatus = 'sent';
|
||||
|
||||
beforeEach(async() => {
|
||||
|
@ -35,10 +34,11 @@ describe('Operator', () => {
|
|||
});
|
||||
|
||||
it('should create notification when delay is null', async() => {
|
||||
const notification = await models.Notification.findOne({where: {name: notificationName}});
|
||||
const {delay} = notification;
|
||||
const config = await models.ProductionConfig.findOne();
|
||||
const delay = config.backupPrinterNotificationDelay;
|
||||
await config.updateAttributes({backupPrinterNotificationDelay: null});
|
||||
const lastNotification = await updateOperatorAndFindNotification();
|
||||
await notification.updateAttributes({delay});
|
||||
await config.updateAttributes({backupPrinterNotificationDelay: delay});
|
||||
|
||||
expect(lastNotification.notificationFk).toEqual(notificationName);
|
||||
});
|
||||
|
@ -58,19 +58,6 @@ describe('Operator', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should send a notification when the previous one is on errorStatus status', async() => {
|
||||
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: errorStatus
|
||||
});
|
||||
const lastNotification = await updateOperatorAndFindNotification();
|
||||
|
||||
expect(lastNotification.notificationFk).toEqual(notificationName);
|
||||
});
|
||||
|
||||
it('should send a notification when the previous one has distinct params', async() => {
|
||||
await models.NotificationQueue.create({
|
||||
authorFk: 2,
|
||||
|
|
|
@ -14,17 +14,14 @@ module.exports = Self => {
|
|||
|
||||
if (sector.backupPrinterFk && sector.backupPrinterFk == instance.labelerFk) {
|
||||
const {labelerFk, sectorFk} = instance;
|
||||
const [{delay}] = await models.Notification.find({where: {name: notificationName}});
|
||||
|
||||
if (delay) {
|
||||
const now = Date.vnNow() - (delay * 1000) + (3600 * 1000);
|
||||
const {backupPrinterNotificationDelay} = await models.ProductionConfig.findOne();
|
||||
if (backupPrinterNotificationDelay) {
|
||||
const notifications = await models.NotificationQueue.find(
|
||||
{where:
|
||||
|
||||
{created: {gte: now},
|
||||
notificationFk: notificationName,
|
||||
status: 'sent'
|
||||
}
|
||||
{where: {created: {gte: Date.vnNow() - (backupPrinterNotificationDelay * 1000) + (3600 * 1000)},
|
||||
notificationFk: notificationName,
|
||||
status: 'sent'
|
||||
}
|
||||
});
|
||||
|
||||
const criteria = {labelerId: labelerFk, sectorId: sectorFk};
|
||||
|
|
Loading…
Reference in New Issue