feat(notification): send
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-07-20 14:54:50 +02:00
parent 7895decf4e
commit 9b48cbb078
10 changed files with 70 additions and 20 deletions

View File

@ -1,7 +1,7 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('send', { Self.remoteMethod('send', {
description: 'Send notifications from queue', description: 'Send notifications from queue',
accessType: 'WRITE', accessType: 'READ',
returns: { returns: {
type: 'object', type: 'object',
root: true root: true
@ -13,6 +13,23 @@ module.exports = Self => {
}); });
Self.send = async() => { 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);
}; };
}; };

View File

@ -77,6 +77,21 @@
"Module": { "Module": {
"dataSource": "vn" "dataSource": "vn"
}, },
"Notification": {
"dataSource": "vn"
},
"NotificationAcl": {
"dataSource": "vn"
},
"NotificationConfig": {
"dataSource": "vn"
},
"NotificationQueue": {
"dataSource": "vn"
},
"NotificationSubscription": {
"dataSource": "vn"
},
"Province": { "Province": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -1,4 +1,3 @@
module.exports = Self => { module.exports = Self => {
require('../methods/notification/send')(Self); require('../methods/notification/send')(Self);
require('../methods/notification/clear')(Self);
}; };

View File

@ -1,9 +1,9 @@
{ {
"name": "Notificacion", "name": "Notification",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "notificacion" "table": "util.notification"
} }
}, },
"properties": { "properties": {

View File

@ -1,16 +1,16 @@
{ {
"name": "NotificacionAcl", "name": "NotificationAcl",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "notificacionAcl" "table": "util.notificationAcl"
} }
}, },
"relations": { "relations": {
"notificacion": { "notification": {
"type": "belongsTo", "type": "belongsTo",
"model": "Notificacion", "model": "Notification",
"foreignKey": "notificacionFk" "foreignKey": "notificationFk"
}, },
"role": { "role": {
"type": "belongsTo", "type": "belongsTo",

View File

@ -3,7 +3,7 @@
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "notificationConfig" "table": "util.notificationConfig"
} }
}, },
"properties": { "properties": {

View File

@ -1,9 +1,9 @@
{ {
"name": "NotificacionQueue", "name": "NotificationQueue",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "notificacionQueue" "table": "util.notificationQueue"
} }
}, },
"properties": { "properties": {
@ -23,10 +23,10 @@
} }
}, },
"relations": { "relations": {
"notificacion": { "notification": {
"type": "belongsTo", "type": "belongsTo",
"model": "Notificacion", "model": "Notification",
"foreignKey": "notificacionFk" "foreignKey": "notificationFk"
}, },
"author": { "author": {
"type": "belongsTo", "type": "belongsTo",

View File

@ -3,14 +3,14 @@
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "notificationSubscription" "table": "util.notificationSubscription"
} }
}, },
"relations": { "relations": {
"notificacion": { "notification": {
"type": "belongsTo", "type": "belongsTo",
"model": "Notificacion", "model": "Notification",
"foreignKey": "notificacionFk" "foreignKey": "notificationFk"
}, },
"user": { "user": {
"type": "belongsTo", "type": "belongsTo",

View File

@ -0,0 +1,3 @@
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('Notification', '*', 'READ', 'ALLOW', 'ROLE', 'developer');

View File

@ -2614,3 +2614,19 @@ INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`,
INSERT INTO `util`.`notificationConfig` INSERT INTO `util`.`notificationConfig`
SET `cleanDays` = 90; 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);