From c87783b4468784d1d3eddcad29951d9b04c04e70 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 13:25:52 +0200 Subject: [PATCH 1/5] 2528 - Rocket notifications hotfix --- back/methods/chat/sendCheckingPresence.js | 18 ++++++++++-------- loopback/locale/en.json | 10 +++++++++- loopback/locale/es.json | 11 +++++++++-- .../back/methods/ticket/componentUpdate.js | 4 +++- .../ticket/specs/componentUpdate.spec.js | 12 +++++++++--- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 6fa029b70..cfae72856 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -3,7 +3,7 @@ module.exports = Self => { description: 'Sends a RocketChat message to a working worker or department channel', accessType: 'WRITE', accepts: [{ - arg: 'workerId', + arg: 'recipientId', type: 'Number', required: true, description: 'The worker id of the destinatary' @@ -23,21 +23,23 @@ module.exports = Self => { } }); - Self.sendCheckingPresence = async(ctx, workerId, message) => { - if (!workerId) return false; + Self.sendCheckingPresence = async(ctx, recipientId, message) => { + if (!recipientId) return false; const models = Self.app.models; - const account = await models.Account.findById(workerId); + const account = await models.Account.findById(recipientId); const userId = ctx.req.accessToken.userId; + if (recipientId == userId) return false; + if (!account) - throw new Error(`Could not send message "${message}" to worker id ${workerId} from user ${userId}`); + throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); const query = `SELECT worker_isWorking(?) isWorking`; - const [result] = await Self.rawSql(query, [workerId]); + const [result] = await Self.rawSql(query, [recipientId]); if (!result.isWorking) { - const workerDepartment = await models.WorkerDepartment.findById(workerId, { + const workerDepartment = await models.WorkerDepartment.findById(recipientId, { include: { relation: 'department' } @@ -46,7 +48,7 @@ module.exports = Self => { const channelName = department && department.chatName; if (channelName) - return Self.send(ctx, `#${channelName}`, `@${account.name} => ${message}`); + return Self.send(ctx, `#${channelName}`, `@${account.name} ➔ ${message}`); } return Self.send(ctx, `@${account.name}`, message); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 7243bccd5..498635832 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -72,5 +72,13 @@ "Deleted absence": "The worker {{author}} has deleted an absence of type '{{absenceType}}' to {{employee}} for day {{dated}}.", "I have deleted the ticket id": "I have deleted the ticket id [{{id}}]({{{url}}})", "I have restored the ticket id": "I have restored the ticket id [{{id}}]({{{url}}})", - "Changed this data from the ticket": "I have changed the data from the ticket [{{ticketId}}]({{{ticketUrl}}}): ```{{{changes}}}```" + "Changed this data from the ticket": "I have changed the data from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", + "agencyModeFk": "Agency", + "clientFk": "Client", + "zoneFk": "Zone", + "warehouseFk": "Warehouse", + "shipped": "Shipped", + "landed": "Landed", + "addressFk": "Address", + "companyFk": "Company" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4a2d48d5e..3fcac3d58 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -140,7 +140,6 @@ "Role already assigned": "Role already assigned", "Invalid role name": "Invalid role name", "Role name must be written in camelCase": "Role name must be written in camelCase", - "can't be set": "can't be set", "Email already exists": "Email already exists", "User already exists": "User already exists", "Absence change notification on the labour calendar": "Notificacion de cambio de ausencia en el calendario laboral", @@ -149,5 +148,13 @@ "I have deleted the ticket id": "He eliminado el ticket id [{{id}}]({{{url}}})", "I have restored the ticket id": "He restaurado el ticket id [{{id}}]({{{url}}})", "You can only restore a ticket within the first hour after deletion": "Únicamente puedes restaurar el ticket dentro de la primera hora después de su eliminación", - "Changed this data from the ticket": "He cambiado estos datos del ticket [{{ticketId}}]({{{ticketUrl}}}): ```{{{changes}}}```" + "Changed this data from the ticket": "He cambiado estos datos del ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", + "agencyModeFk": "Agencia", + "clientFk": "Cliente", + "zoneFk": "Zona", + "warehouseFk": "Almacén", + "shipped": "F. envío", + "landed": "F. entrega", + "addressFk": "Consignatario", + "companyFk": "Empresa" } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 9010fc3ac..91d867a30 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -140,6 +140,7 @@ module.exports = Self => { let changesMade = ''; for (let change in changedProperties) { let value = changedProperties[change]; + let oldValue = originalTicket[change]; if (value instanceof Date) { value = new Intl.DateTimeFormat('es', { year: '2-digit', @@ -149,9 +150,10 @@ module.exports = Self => { minute: '2-digit', second: '2-digit' }).format(value); + oldValue = value; } - changesMade += `${change}: ${value}\r\n`; + changesMade += `\r\n~${$t(change)}: ${value}~ ➔ *${$t(change)}: ${oldValue}*`; } const message = $t('Changed this data from the ticket', { diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 55dd29c16..256def165 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -45,8 +45,8 @@ describe('ticket componentUpdate()', () => { req: { accessToken: {userId: 101}, headers: {origin: 'http://localhost'}, - __: (value, params) => { - return params.nickname; + __: value => { + return value; } } }; @@ -79,7 +79,13 @@ describe('ticket componentUpdate()', () => { let ctx = { args: {clientFk: 102, agencyModeFk: 7}, - req: {accessToken: {userId: 101}}}; + req: { + accessToken: {userId: 101}, + headers: {origin: 'http://localhost'}, + __: value => { + return value; + } + }}; await app.models.Ticket.componentUpdate(ctx, ticketId, clientId, agencyModeId, addressId, zoneId, warehouseId, companyId, shipped, landed, isDeleted, option); From 628154b7e89601c4c5f8cb9fca53fae19196f26d Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 13:40:54 +0200 Subject: [PATCH 2/5] Trigger jenkins --- modules/ticket/back/methods/ticket/componentUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 91d867a30..3edecbd61 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -103,7 +103,7 @@ module.exports = Self => { delete updatedTicket.ctx; delete updatedTicket.option; - // Force unroute + // Force to unroute ticket const hasToBeUnrouted = true; const changedProperties = diff(originalTicket, updatedTicket); From 537d61e27ec860ff73f0f3008e73b52a5795f2f6 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 13:53:46 +0200 Subject: [PATCH 3/5] Updated locale --- loopback/locale/es.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 3fcac3d58..c3fe287eb 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -121,11 +121,11 @@ "Swift / BIC can't be empty": "Swift / BIC no puede estar vacío", "Customs agent is required for a non UEE member": "El agente de aduanas es requerido para los clientes extracomunitarios", "Incoterms is required for a non UEE member": "El incoterms es requerido para los clientes extracomunitarios", - "MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} (#{{itemId}}) para el ticket id [{{ticketId}}]({{{url}}})", - "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*", - "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})", - "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", - "Claim will be picked": "Se recogerá el género de la reclamación (#{{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", + "MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} ({{itemId}}) para el ticket id [{{ticketId}}]({{{url}}})", + "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} ({{clientId}})]({{{url}}}) a *{{credit}} €*", + "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} ({{clientId}})]({{{url}}})", + "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} ({{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", + "Claim will be picked": "Se recogerá el género de la reclamación ({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", "This ticket is not an stowaway anymore": "El ticket id [{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", From d3532608e13c2c61cd3b4bd9e8ee986fa5a1579f Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 14:05:14 +0200 Subject: [PATCH 4/5] Changed oldValue --- .../ticket/back/methods/ticket/componentUpdate.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 3edecbd61..6947cdc3b 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -150,10 +150,20 @@ module.exports = Self => { minute: '2-digit', second: '2-digit' }).format(value); - oldValue = value; } - changesMade += `\r\n~${$t(change)}: ${value}~ ➔ *${$t(change)}: ${oldValue}*`; + if (oldValue instanceof Date) { + oldValue = new Intl.DateTimeFormat('es', { + year: '2-digit', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }).format(oldValue); + } + + changesMade += `\r\n~${$t(change)}: ${oldValue}~ ➔ *${$t(change)}: ${value}*`; } const message = $t('Changed this data from the ticket', { From b5c5d78d3aaeb9cd040b9d2e3598ffb7e1820fec Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 14:51:07 +0200 Subject: [PATCH 5/5] Param name hotfix --- back/methods/chat/sendCheckingPresence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index cfae72856..8f682bb66 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -3,7 +3,7 @@ module.exports = Self => { description: 'Sends a RocketChat message to a working worker or department channel', accessType: 'WRITE', accepts: [{ - arg: 'recipientId', + arg: 'workerId', type: 'Number', required: true, description: 'The worker id of the destinatary'