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 => {
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);
};
};

View File

@ -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"
},

View File

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

View File

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

View File

@ -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",

View File

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

View File

@ -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",

View File

@ -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",

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`
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);