feat(notification): create models
gitea/salix/pipeline/head This commit is unstable Details

This commit is contained in:
Alex Moreno 2022-07-19 15:17:22 +02:00
parent f1c3a3f721
commit 7895decf4e
10 changed files with 214 additions and 4 deletions

View File

View File

@ -0,0 +1,18 @@
module.exports = Self => {
Self.remoteMethod('send', {
description: 'Send notifications from queue',
accessType: 'WRITE',
returns: {
type: 'object',
root: true
},
http: {
path: `/send`,
verb: 'POST'
}
});
Self.send = async() => {
};
};

View File

@ -0,0 +1,22 @@
{
"name": "Notificacion",
"base": "VnModel",
"options": {
"mysql": {
"table": "notificacion"
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
}
}
}

View File

@ -0,0 +1,21 @@
{
"name": "NotificacionAcl",
"base": "VnModel",
"options": {
"mysql": {
"table": "notificacionAcl"
}
},
"relations": {
"notificacion": {
"type": "belongsTo",
"model": "Notificacion",
"foreignKey": "notificacionFk"
},
"role": {
"type": "belongsTo",
"model": "Role",
"foreignKey": "roleFk"
}
}
}

View File

@ -0,0 +1,19 @@
{
"name": "NotificationConfig",
"base": "VnModel",
"options": {
"mysql": {
"table": "notificationConfig"
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"cleanDays": {
"type": "number"
}
}
}

View File

@ -0,0 +1,37 @@
{
"name": "NotificacionQueue",
"base": "VnModel",
"options": {
"mysql": {
"table": "notificacionQueue"
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"params": {
"type": "string"
},
"status": {
"type": "string"
},
"created": {
"type": "date"
}
},
"relations": {
"notificacion": {
"type": "belongsTo",
"model": "Notificacion",
"foreignKey": "notificacionFk"
},
"author": {
"type": "belongsTo",
"model": "User",
"foreignKey": "authorFk"
}
}
}

View File

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

View File

@ -0,0 +1,21 @@
{
"name": "NotificationSubscription",
"base": "VnModel",
"options": {
"mysql": {
"table": "notificationSubscription"
}
},
"relations": {
"notificacion": {
"type": "belongsTo",
"model": "Notificacion",
"foreignKey": "notificacionFk"
},
"user": {
"type": "belongsTo",
"model": "User",
"foreignKey": "userFk"
}
}
}

View File

@ -2611,3 +2611,6 @@ INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk
INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`)
VALUES
(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;

View File

@ -20849,9 +20849,74 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `util` /*!40100 DEFAULT CHARACTER SET u
USE `util`;
--
-- Table structure for table `config`
--
CREATE TABLE notification(
id INT PRIMARY KEY,
`name` VARCHAR(255) UNIQUE,
`description` VARCHAR(255)
);
CREATE TABLE notificationAcl (
notificationFk INT(11),
roleFk INT(10) unsigned,
PRIMARY KEY(notificationFk, roleFk),
CONSTRAINT `notificationAcl_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `notificationAcl_ibfk_2` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE notificationSubscription(
notificationFk INT,
userFk INT(10) unsigned,
PRIMARY KEY(notificationFk, userFk),
CONSTRAINT `notificationSubscription_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `notificationSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE notificationQueue(
id INT PRIMARY KEY AUTO_INCREMENT,
notificationFk VARCHAR(255),
params TEXT,
authorFk INT(10) unsigned NULL,
`status` ENUM('pending', 'sent', 'error') NOT NULL DEFAULT 'pending',
created DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX(notificationFk),
INDEX(authorFk),
INDEX(status),
CONSTRAINT `notificationQueue_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `notificationQueue_ibfk_2` FOREIGN KEY (`authorFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE notificationConfig(
id INT PRIMARY KEY AUTO_INCREMENT,
cleanDays MEDIUMINT
);
DROP FUNCTION IF EXISTS util.notification_send;
DELIMITER $$
CREATE FUNCTION util.notification_send(vNotificationName VARCHAR(255), vParams TEXT, vAuthorFk INT)
RETURNS INT
BEGIN
/**
* Sends a notification.
*
* @param vNotificationName The notification name
* @param vParams The notification parameters formatted as JSON
* @param vAuthorFk The notification author or %NULL if there is no author
* @return The notification id
*/
DECLARE vNotificationFk INT;
SELECT id INTO vNotificationFk
FROM `notification`
WHERE `name` = vNotificationName;
INSERT INTO notificationQueue
SET notificationFk = vNotificationFk,
params = vParams,
authorFk = vAuthorFk;
RETURN LAST_INSERT_ID();
END$$
DELIMITER ;
DROP TABLE IF EXISTS `config`;
/*!40101 SET @saved_cs_client = @@character_set_client */;