From 9b48cbb07866be87502d33cee7d6648243606a0d Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 20 Jul 2022 14:54:50 +0200 Subject: [PATCH] feat(notification): send --- back/methods/notification/send.js | 19 ++++++++++++++++++- back/model-config.json | 15 +++++++++++++++ back/models/notification.js | 1 - .../{notifcation.json => notification.json} | 4 ++-- ...tifcationAcl.json => notificationAcl.json} | 10 +++++----- ...ionConfig.json => notificationConfig.json} | 2 +- ...ationQueue.json => notificationQueue.json} | 10 +++++----- back/models/notificationSubscription.json | 8 ++++---- .../10490-goldenSummer/00-aclNotification.sql | 3 +++ db/dump/fixtures.sql | 18 +++++++++++++++++- 10 files changed, 70 insertions(+), 20 deletions(-) rename back/models/{notifcation.json => notification.json} (84%) rename back/models/{notifcationAcl.json => notificationAcl.json} (59%) rename back/models/{notifcationConfig.json => notificationConfig.json} (88%) rename back/models/{notifcationQueue.json => notificationQueue.json} (76%) create mode 100644 db/changes/10490-goldenSummer/00-aclNotification.sql diff --git a/back/methods/notification/send.js b/back/methods/notification/send.js index bb2d79f2a..d5149fc59 100644 --- a/back/methods/notification/send.js +++ b/back/methods/notification/send.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethod('send', { description: 'Send notifications from queue', - accessType: 'WRITE', + accessType: 'READ', returns: { type: 'object', root: true @@ -13,6 +13,23 @@ module.exports = Self => { }); Self.send = async() => { + const status = 'pending'; + const myOptions = {}; + let tx; + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + const notificationQueue = await Self.app.models.NotificationQueue.find({ + where: {code: status}, + include: [{ + relation: 'notificationSubscription' + }] + }, myOptions); + + console.log(notificationQueue); }; }; diff --git a/back/model-config.json b/back/model-config.json index 343210383..755f449de 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -77,6 +77,21 @@ "Module": { "dataSource": "vn" }, + "Notification": { + "dataSource": "vn" + }, + "NotificationAcl": { + "dataSource": "vn" + }, + "NotificationConfig": { + "dataSource": "vn" + }, + "NotificationQueue": { + "dataSource": "vn" + }, + "NotificationSubscription": { + "dataSource": "vn" + }, "Province": { "dataSource": "vn" }, diff --git a/back/models/notification.js b/back/models/notification.js index da766d442..46378bd02 100644 --- a/back/models/notification.js +++ b/back/models/notification.js @@ -1,4 +1,3 @@ module.exports = Self => { require('../methods/notification/send')(Self); - require('../methods/notification/clear')(Self); }; diff --git a/back/models/notifcation.json b/back/models/notification.json similarity index 84% rename from back/models/notifcation.json rename to back/models/notification.json index e4f0be17e..9422d03b3 100644 --- a/back/models/notifcation.json +++ b/back/models/notification.json @@ -1,9 +1,9 @@ { - "name": "Notificacion", + "name": "Notification", "base": "VnModel", "options": { "mysql": { - "table": "notificacion" + "table": "util.notification" } }, "properties": { diff --git a/back/models/notifcationAcl.json b/back/models/notificationAcl.json similarity index 59% rename from back/models/notifcationAcl.json rename to back/models/notificationAcl.json index f5861943f..e3e97f52d 100644 --- a/back/models/notifcationAcl.json +++ b/back/models/notificationAcl.json @@ -1,16 +1,16 @@ { - "name": "NotificacionAcl", + "name": "NotificationAcl", "base": "VnModel", "options": { "mysql": { - "table": "notificacionAcl" + "table": "util.notificationAcl" } }, "relations": { - "notificacion": { + "notification": { "type": "belongsTo", - "model": "Notificacion", - "foreignKey": "notificacionFk" + "model": "Notification", + "foreignKey": "notificationFk" }, "role": { "type": "belongsTo", diff --git a/back/models/notifcationConfig.json b/back/models/notificationConfig.json similarity index 88% rename from back/models/notifcationConfig.json rename to back/models/notificationConfig.json index 73882b6b7..b00ed3675 100644 --- a/back/models/notifcationConfig.json +++ b/back/models/notificationConfig.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "notificationConfig" + "table": "util.notificationConfig" } }, "properties": { diff --git a/back/models/notifcationQueue.json b/back/models/notificationQueue.json similarity index 76% rename from back/models/notifcationQueue.json rename to back/models/notificationQueue.json index 7a9199bc0..122d3816d 100644 --- a/back/models/notifcationQueue.json +++ b/back/models/notificationQueue.json @@ -1,9 +1,9 @@ { - "name": "NotificacionQueue", + "name": "NotificationQueue", "base": "VnModel", "options": { "mysql": { - "table": "notificacionQueue" + "table": "util.notificationQueue" } }, "properties": { @@ -23,10 +23,10 @@ } }, "relations": { - "notificacion": { + "notification": { "type": "belongsTo", - "model": "Notificacion", - "foreignKey": "notificacionFk" + "model": "Notification", + "foreignKey": "notificationFk" }, "author": { "type": "belongsTo", diff --git a/back/models/notificationSubscription.json b/back/models/notificationSubscription.json index ed8bb1907..14b305ca8 100644 --- a/back/models/notificationSubscription.json +++ b/back/models/notificationSubscription.json @@ -3,14 +3,14 @@ "base": "VnModel", "options": { "mysql": { - "table": "notificationSubscription" + "table": "util.notificationSubscription" } }, "relations": { - "notificacion": { + "notification": { "type": "belongsTo", - "model": "Notificacion", - "foreignKey": "notificacionFk" + "model": "Notification", + "foreignKey": "notificationFk" }, "user": { "type": "belongsTo", diff --git a/db/changes/10490-goldenSummer/00-aclNotification.sql b/db/changes/10490-goldenSummer/00-aclNotification.sql new file mode 100644 index 000000000..aa4e32cee --- /dev/null +++ b/db/changes/10490-goldenSummer/00-aclNotification.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Notification', '*', 'READ', 'ALLOW', 'ROLE', 'developer'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index dabc73139..f73210a96 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2613,4 +2613,20 @@ INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, (1, 43200, 32400, 129600, 259200, 604800, '', '', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.33, 0.33, 40, '22:00:00', '06:00:00', 57600, 1200, 18000, 57600, 6, 13); INSERT INTO `util`.`notificationConfig` - SET `cleanDays` = 90; \ No newline at end of file + SET `cleanDays` = 90; + +INSERT INTO `util`.`notification` (`id`, `name`, `description`) + VALUES + (1, 'notification one', 'notification fixture one'); + +INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) + VALUES + (1, 9); + +INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`) + VALUES + (1, 'notification one', 'randomParams', 9, 'pending', util.VN_CURDATE()); + +INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) + VALUES + (1, 1110); \ No newline at end of file