OsTicket notifications
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-04-12 07:48:29 +02:00
parent 9bbf43c590
commit 6eba19a1b7
6 changed files with 48 additions and 11 deletions

View File

@ -15,15 +15,21 @@ module.exports = Self => {
Self.notifyIssues = async ctx => {
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const [urgentIssue] = await Self.rawSql(`
SELECT * FROM managedesktop.vn_workOrderInmediata LIMIT 1
const tickets = await models.OsTicket.rawSql(`
SELECT t.ticket_id AS id, t.number, ua.username, td.subject
FROM ost_ticket t
JOIN ost_user_account ua ON t.user_id = ua.user_id
JOIN ost_ticket__cdata td ON t.ticket_id = td.ticket_id
JOIN ost_ticket_priority tp ON td.priority = tp.priority_id
WHERE tp.priority = 'emergency' AND t.staff_id = 0
`);
if (!urgentIssue) return;
if (!tickets.length) return;
const message = $t(`There's a new urgent ticket`, {
title: urgentIssue.title,
issueId: urgentIssue.workOrderId
let message = $t(`There's a new urgent ticket:`);
const ostUri = 'https://cau.verdnatura.es/scp/tickets.php?id=';
tickets.forEach(ticket => {
message += `\r\n[ID: *${ticket.number}* - ${ticket.subject} (@${ticket.username})](${ostUri + ticket.id})`;
});
const department = await models.Department.findOne({

View File

@ -6,11 +6,12 @@ describe('Chat notifyIssue()', () => {
return value;
};
const chatModel = app.models.Chat;
const osTicketModel = app.models.OsTicket;
const departmentId = 31;
it(`should not call to the send() method and neither return a response`, async() => {
spyOn(chatModel, 'send').and.callThrough();
spyOn(chatModel, 'rawSql').and.returnValue([]);
spyOn(osTicketModel, 'rawSql').and.returnValue([]);
const response = await chatModel.notifyIssues(ctx);
@ -20,7 +21,13 @@ describe('Chat notifyIssue()', () => {
it(`should return a response calling the send() method`, async() => {
spyOn(chatModel, 'send').and.callThrough();
spyOn(chatModel, 'rawSql').and.returnValue([{title: 'Issue title'}]);
spyOn(osTicketModel, 'rawSql').and.returnValue([{
id: 1,
number: '00001',
username: 'batman',
subject: 'Issue title'}
]);
const expectedMessage = `@all ➔ There's a new urgent ticket:\r\n[ID: *00001* - Issue title (@batman)](https://osticket.verdnatura.es/scp/tickets.php?id=1)`;
const department = await app.models.Department.findById(departmentId);
let orgChatName = department.chatName;
@ -30,7 +37,7 @@ describe('Chat notifyIssue()', () => {
expect(response.statusCode).toEqual(200);
expect(response.message).toEqual('Fake notification sent');
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', `@all ➔ There's a new urgent ticket`);
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', expectedMessage);
// restores
await department.updateAttribute('chatName', orgChatName);

View File

@ -94,6 +94,9 @@
},
"Warehouse": {
"dataSource": "vn"
},
"OsTicket": {
"dataSource": "osticket"
}
}

12
back/models/osticket.json Normal file
View File

@ -0,0 +1,12 @@
{
"name": "OsTicket",
"base": "VnModel",
"acls": [{
"property": "validations",
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}]
}

View File

@ -172,7 +172,7 @@
"Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío",
"This BIC already exist.": "Este BIC ya existe.",
"That item doesn't exists": "Ese artículo no existe",
"There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})",
"There's a new urgent ticket:": "Hay un nuevo ticket urgente:",
"Invalid account": "Cuenta inválida",
"Compensation account is empty": "La cuenta para compensar está vacia",
"This genus already exist": "Este genus ya existe",

View File

@ -17,6 +17,15 @@
"connectTimeout": 40000,
"acquireTimeout": 20000
},
"osticket": {
"connector": "vn-mysql",
"database": "vn",
"debug": false,
"host": "localhost",
"port": "3306",
"username": "root",
"password": "root"
},
"tempStorage": {
"name": "tempStorage",
"connector": "loopback-component-storage",