7253-devToTest_2418 #2350
|
@ -3,7 +3,7 @@
|
||||||
// Carácter predeterminado de final de línea.
|
// Carácter predeterminado de final de línea.
|
||||||
"files.eol": "\n",
|
"files.eol": "\n",
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": "explicit"
|
||||||
},
|
},
|
||||||
"search.useIgnoreFiles": false,
|
"search.useIgnoreFiles": false,
|
||||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
||||||
|
|
|
@ -2,11 +2,11 @@ const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('NotificationSubscription getList()', () => {
|
describe('NotificationSubscription getList()', () => {
|
||||||
it('should return a list of available and active notifications of a user', async() => {
|
it('should return a list of available and active notifications of a user', async() => {
|
||||||
const {active, available} = await models.NotificationSubscription.getList(100);
|
const {active, available} = await models.NotificationSubscription.getList(9);
|
||||||
const notifications = await models.Notification.find({});
|
const notifications = await models.Notification.find({});
|
||||||
const totalAvailable = notifications.length - active.length;
|
const totalAvailable = notifications.length - active.length;
|
||||||
|
|
||||||
expect(active.length).toEqual(1);
|
expect(active.length).toEqual(2);
|
||||||
expect(available.length).toEqual(totalAvailable);
|
expect(available.length).toEqual(totalAvailable);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
};
|
|
@ -92,7 +92,7 @@ describe('loopback model NotificationSubscription', () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx, accessToken: {userId: 9}};
|
const options = {transaction: tx, accessToken: {userId: 9}};
|
||||||
await models.NotificationSubscription.create({notificationFk: 12, userFk: 5}, options);
|
await models.NotificationSubscription.create({notificationFk: 1, userFk: 5}, options);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
ALTER TABLE `vn`.`packingSite` DROP FOREIGN KEY `packingSite_FK_4`;
|
||||||
|
ALTER TABLE `vn`.`arcRead` DROP FOREIGN KEY `worker_printer_FK`;
|
||||||
|
ALTER TABLE `vn`.`host` DROP FOREIGN KEY `configHost_FK`;
|
||||||
|
ALTER TABLE `vn`.`operator` DROP FOREIGN KEY `operator_FK_5`;
|
||||||
|
ALTER TABLE `vn`.`packingSite` DROP FOREIGN KEY `packingSite_FK_1`;
|
||||||
|
ALTER TABLE `vn`.`printQueue` DROP FOREIGN KEY `printQueue_printerFk`;
|
||||||
|
ALTER TABLE `vn`.`sector` DROP FOREIGN KEY `sector_FK_1`;
|
||||||
|
ALTER TABLE `vn`.`worker` DROP FOREIGN KEY `worker_FK`;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
ALTER TABLE `vn`.`printer` MODIFY COLUMN `id` int unsigned auto_increment NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`arcRead` MODIFY COLUMN `printerFk` int unsigned DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`arcRead` ADD CONSTRAINT `arcRead_FK` FOREIGN KEY (printerFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`host` MODIFY COLUMN `printerFk` int unsigned DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`host` ADD CONSTRAINT `host_FK` FOREIGN KEY (printerFk) REFERENCES vn.printer(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`operator` MODIFY COLUMN `labelerFk` int unsigned DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`operator` ADD CONSTRAINT `operator_FK_4` FOREIGN KEY (labelerFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`packingSite` MODIFY COLUMN `printerRfidFk` int unsigned DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`packingSite` MODIFY COLUMN `printerFk` int unsigned DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`packingSite` ADD CONSTRAINT `packingSite_FK_1` FOREIGN KEY (printerFk) REFERENCES vn.printer(id) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
||||||
|
ALTER TABLE `vn`.`packingSite` ADD CONSTRAINT `packingSite_FK_4` FOREIGN KEY (printerRfidFk) REFERENCES vn.printer(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`printQueue` MODIFY COLUMN `printerFk` int unsigned DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`printQueue` ADD CONSTRAINT `printQueue_FK` FOREIGN KEY (id) REFERENCES vn.printer(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`sector` MODIFY COLUMN `mainPrinterFk` int unsigned DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`sector` ADD CONSTRAINT `sector_FK` FOREIGN KEY (mainPrinterFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -1,7 +1,9 @@
|
||||||
ALTER TABLE `util`.`notification` ADD delay INT NULL
|
ALTER TABLE `util`.`notification` ADD delay INT NULL
|
||||||
COMMENT 'Minimum Milliseconds Interval to Prevent Spam from Same-Type Notifications';
|
COMMENT 'Minimum Milliseconds Interval to Prevent Spam from Same-Type Notifications';
|
||||||
|
|
||||||
ALTER TABLE `vn`.`sector` CHANGE `mainPrinterFk` `backupPrinterFk` tinyint(3) unsigned DEFAULT NULL NULL;
|
ALTER TABLE vn.sector DROP FOREIGN KEY sector_FK;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`sector` CHANGE `mainPrinterFk` `backupPrinterFk` int unsigned DEFAULT NULL NULL;
|
||||||
|
|
||||||
ALTER TABLE `util`.`notificationSubscription` DROP FOREIGN KEY `notificationSubscription_ibfk_1`;
|
ALTER TABLE `util`.`notificationSubscription` DROP FOREIGN KEY `notificationSubscription_ibfk_1`;
|
||||||
ALTER TABLE `util`.`notificationQueue` DROP FOREIGN KEY `nnotificationQueue_ibfk_1`;
|
ALTER TABLE `util`.`notificationQueue` DROP FOREIGN KEY `nnotificationQueue_ibfk_1`;
|
||||||
|
@ -13,18 +15,4 @@ ALTER TABLE `util`.`notificationSubscription` ADD CONSTRAINT `notificationSubscr
|
||||||
ALTER TABLE `util`.`notificationQueue` ADD CONSTRAINT `notificationQueue_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`name`) ON DELETE CASCADE ON UPDATE CASCADE;
|
ALTER TABLE `util`.`notificationQueue` ADD CONSTRAINT `notificationQueue_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`name`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
ALTER TABLE `util`.`notificationAcl` ADD CONSTRAINT `notificationAcl_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
ALTER TABLE `util`.`notificationAcl` ADD CONSTRAINT `notificationAcl_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
DELETE FROM `util`.`notification`
|
|
||||||
WHERE `name` = 'not-main-printer-configured';
|
|
||||||
|
|
||||||
INSERT INTO `util`.`notification`
|
|
||||||
SET `name` = 'backup-printer-selected',
|
|
||||||
`description` = 'The worker has selected the backup printer for their sector',
|
|
||||||
`delay` = 600000;
|
|
||||||
|
|
||||||
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
|
|
||||||
SELECT `n`.`id`, `r`.`id`
|
|
||||||
FROM `util`.`notification` `n`
|
|
||||||
JOIN `account`.`role` `r`
|
|
||||||
WHERE `n`.`name` = 'backup-printer-selected'
|
|
||||||
AND `r`.`name` = 'system'
|
|
||||||
LIMIT 1;
|
|
|
@ -233,33 +233,6 @@ LOCK TABLES `agencyTermConfig` WRITE;
|
||||||
INSERT INTO `agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios');
|
INSERT INTO `agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios');
|
||||||
/*!40000 ALTER TABLE `agencyTermConfig` ENABLE KEYS */;
|
/*!40000 ALTER TABLE `agencyTermConfig` ENABLE KEYS */;
|
||||||
UNLOCK TABLES;
|
UNLOCK TABLES;
|
||||||
|
|
||||||
LOCK TABLES `notification` WRITE;
|
|
||||||
INSERT INTO `util`.`notification` (id, name, description)
|
|
||||||
VALUES(1, 'vehicle-event-expired', 'scheduled event of a vehicle'),
|
|
||||||
(2, 'invoice-electronic', 'A electronic invoice has been generated'),
|
|
||||||
(3, 'supplier-pay-method-update', 'A supplier pay method has been updated'),
|
|
||||||
(4, 'book-entries-imported-incorrectly', 'accounting entries exported incorrectly'),
|
|
||||||
(5, 'greuge-wrong', 'A wrong greuge has been created'),
|
|
||||||
(6, 'not-main-printer-configured', 'A printer distinct than main has been configured'),
|
|
||||||
(7, 'entry-update-comission', 'entry change comission'),
|
|
||||||
(8, 'modified-entry', 'An entry has been modified'),
|
|
||||||
(9, 'book-entry-deleted', 'accounting entries deleted'),
|
|
||||||
(10, 'modified-collection-volumetry', 'A collection volumetry has been modified');
|
|
||||||
UNLOCK TABLES;
|
|
||||||
|
|
||||||
LOCK TABLES `notificationAcl` WRITE;
|
|
||||||
INSERT INTO `util`.`notificationAcl` (notificationFk, roleFk)
|
|
||||||
VALUES(1, 57),
|
|
||||||
(3, 73),
|
|
||||||
(4, 5),
|
|
||||||
(6, 108),
|
|
||||||
(7, 30),
|
|
||||||
(7, 35),
|
|
||||||
(8, 15),
|
|
||||||
(9, 5);
|
|
||||||
UNLOCK TABLES;
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Dumping data for table `alertLevel`
|
-- Dumping data for table `alertLevel`
|
||||||
--
|
--
|
||||||
|
|
|
@ -2788,32 +2788,40 @@ INSERT INTO `vn`.`packingSiteConfig` (`shinobiUrl`, `shinobiToken`, `shinobiGrou
|
||||||
INSERT INTO `util`.`notificationConfig`
|
INSERT INTO `util`.`notificationConfig`
|
||||||
SET `cleanDays` = 90;
|
SET `cleanDays` = 90;
|
||||||
|
|
||||||
INSERT IGNORE INTO `util`.`notification` (`name`, `description`, `delay`)
|
INSERT INTO `util`.`notification` (`id`, `name`, `description`, `delay`)
|
||||||
VALUES ('print-email', 'notification fixture one', NULL);
|
VALUES (1, 'print-email', 'notification fixture one', NULL),
|
||||||
|
(2, 'invoice-electronic', 'A electronic invoice has been generated', NULL),
|
||||||
|
(3, 'backup-printer-selected', 'A printer distinct than main has been configured', 600000),
|
||||||
|
(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);
|
||||||
|
|
||||||
INSERT INTO `util`.`notificationQueue` (`notificationFk`, `params`, `authorFk`, `status`, `created`)
|
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
|
||||||
VALUES ('print-email', '{"id": "1"}', 9, 'pending', util.VN_CURDATE()),
|
VALUES
|
||||||
('print-email', '{"id": "2"}', null, 'pending', util.VN_CURDATE()),
|
(1, 9),
|
||||||
('print-email', null, null, 'pending', util.VN_CURDATE());
|
(1, 1),
|
||||||
|
(2, 1),
|
||||||
|
(3, 9),
|
||||||
|
(4, 1),
|
||||||
|
(5, 9),
|
||||||
|
(6, 9);
|
||||||
|
|
||||||
|
INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`)
|
||||||
|
VALUES
|
||||||
|
(1, 'print-email', '{"id": "1"}', 9, 'pending', util.VN_CURDATE()),
|
||||||
|
(2, 'print-email', '{"id": "2"}', null, 'pending', util.VN_CURDATE()),
|
||||||
|
(3, 'print-email', null, null, 'pending', util.VN_CURDATE());
|
||||||
|
|
||||||
INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`)
|
INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`)
|
||||||
VALUES (12, 1109),
|
VALUES
|
||||||
(12, 1110),
|
(1, 1109),
|
||||||
|
(1, 1110),
|
||||||
(2, 1110),
|
(2, 1110),
|
||||||
(4, 1110),
|
(4, 1110),
|
||||||
(2, 1109),
|
(2, 1109),
|
||||||
(12, 9),
|
(1, 9),
|
||||||
(12, 3),
|
(1, 3),
|
||||||
(12, 100);
|
(6, 9);
|
||||||
|
|
||||||
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
|
|
||||||
VALUES (12, 9),
|
|
||||||
(12, 1),
|
|
||||||
(4, 1),
|
|
||||||
(2, 1),
|
|
||||||
(3, 9),
|
|
||||||
(5, 9),
|
|
||||||
(10,1);
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
|
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -16,8 +16,6 @@ TABLES=(
|
||||||
config
|
config
|
||||||
version
|
version
|
||||||
versionLog
|
versionLog
|
||||||
notification
|
|
||||||
notificationAcl
|
|
||||||
)
|
)
|
||||||
dump_tables ${TABLES[@]}
|
dump_tables ${TABLES[@]}
|
||||||
|
|
||||||
|
|
|
@ -74,9 +74,15 @@ describe('Operator', () => {
|
||||||
created: Date.vnNow(),
|
created: Date.vnNow(),
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
const notificationQueue = await createOperator(labeler, options);
|
let error;
|
||||||
|
|
||||||
expect(notificationQueue).toEqual(null);
|
try {
|
||||||
|
await createOperator(labeler, options);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual('Is already Notified');
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ module.exports = function(Self) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const options = ctx.options;
|
const options = ctx.options;
|
||||||
const notification = 'backup-printer-selected';
|
const notification = 'backup-printer-selected';
|
||||||
|
const {userId} = ctx.options.accessToken;
|
||||||
|
|
||||||
if (!instance?.sectorFk || !instance?.labelerFk) return;
|
if (!instance?.sectorFk || !instance?.labelerFk) return;
|
||||||
|
|
||||||
|
@ -12,34 +13,17 @@ module.exports = function(Self) {
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
if (sector.backupPrinterFk && sector.backupPrinterFk == instance.labelerFk) {
|
if (sector.backupPrinterFk && sector.backupPrinterFk == instance.labelerFk) {
|
||||||
const {userId} = ctx.options.accessToken;
|
await models.NotificationQueue.create({
|
||||||
const {delay} = await models.Notification.findOne({
|
notificationFk: notification,
|
||||||
where: {name: notification}
|
authorFk: userId,
|
||||||
|
params: JSON.stringify(
|
||||||
|
{
|
||||||
|
'labelerId': instance.labelerFk,
|
||||||
|
'sectorId': instance.sectorFk,
|
||||||
|
'workerId': userId
|
||||||
|
}
|
||||||
|
)
|
||||||
}, options);
|
}, options);
|
||||||
const hasNotified = await models.NotificationQueue.findOne({
|
|
||||||
where: {
|
|
||||||
notificationFk: notification,
|
|
||||||
and: [
|
|
||||||
{params: {like: '%\"labelerId\":' + instance.labelerFk + '%'}},
|
|
||||||
{params: {like: '%\"sectorId\":' + instance.sectorFk + '%'}}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
order: 'created DESC',
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
if (hasNotified?.created - Date.now() > delay || !hasNotified?.created || !delay) {
|
|
||||||
await models.NotificationQueue.create({
|
|
||||||
notificationFk: notification,
|
|
||||||
authorFk: userId,
|
|
||||||
params: JSON.stringify(
|
|
||||||
{
|
|
||||||
'labelerId': instance.labelerFk,
|
|
||||||
'sectorId': instance.sectorFk,
|
|
||||||
'workerId': userId
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}, options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue