diff --git a/back/methods/chat/notifyIssues.js b/back/methods/chat/notifyIssues.js index 54eb41c89..b0a42b7be 100644 --- a/back/methods/chat/notifyIssues.js +++ b/back/methods/chat/notifyIssues.js @@ -15,15 +15,24 @@ 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 + LEFT JOIN ost_department dept ON dept.id = t.dept_id + WHERE tp.priority = 'emergency' + AND (t.staff_id = 0 AND t.team_id = 0) + AND dept.code = 'IT' + `); - 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({ diff --git a/back/methods/chat/spec/notifyIssue.spec.js b/back/methods/chat/spec/notifyIssue.spec.js index e23c33859..96117c2c0 100644 --- a/back/methods/chat/spec/notifyIssue.spec.js +++ b/back/methods/chat/spec/notifyIssue.spec.js @@ -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://cau.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); diff --git a/back/model-config.json b/back/model-config.json index 418cd4d1f..bf473d7bc 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -94,6 +94,9 @@ }, "Warehouse": { "dataSource": "vn" + }, + "OsTicket": { + "dataSource": "osticket" } } diff --git a/back/models/osticket.json b/back/models/osticket.json new file mode 100644 index 000000000..0c673d004 --- /dev/null +++ b/back/models/osticket.json @@ -0,0 +1,12 @@ +{ + "name": "OsTicket", + "base": "VnModel", + "acls": [{ + "property": "validations", + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }] +} + \ No newline at end of file diff --git a/front/core/components/field/index.js b/front/core/components/field/index.js index e10ef6383..40ea01e47 100644 --- a/front/core/components/field/index.js +++ b/front/core/components/field/index.js @@ -83,9 +83,6 @@ export default class Field extends FormInput { this._required = value; let required = this.element.querySelector('.required'); display(required, this._required); - - this.$.$applyAsync(() => - this.input.setAttribute('required', value)); } get required() { diff --git a/loopback/locale/es.json b/loopback/locale/es.json index cef64b43a..fdc1bd977 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -173,7 +173,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", diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index 343bcedd8..87fff60e1 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -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", diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 09783ec20..8ea08898f 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -165,13 +165,13 @@ class Controller extends Section { created: this.ticket.updated }; this.showSMSDialog({ - message: this.$params.message || this.$t('Minimum is needed', params) + message: this.$t('Minimum is needed', params) }); } sendPaymentSms() { this.showSMSDialog({ - message: this.$params.message || this.$t('Make a payment') + message: this.$t('Make a payment') }); } diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 2f3a65812..46cbe43c9 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -27,9 +27,12 @@ class Controller extends Section { } get ticketState() { - if (!this.ticket) return null; + const ticket = this.ticket; + if (!ticket) return null; - return this.ticket.ticketState.state.code; + const ticketState = ticket.ticketState; + + return ticketState && ticketState.state.code; } getSaleTotal(sale) {