From d94e2900d0e4795a96f6c2ed3e9e6afa4942924d Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 27 Oct 2021 12:16:37 +0200 Subject: [PATCH 1/7] feat(ticket-request): send rocket message when ticket-reques is denied --- loopback/locale/es.json | 1 + .../ticket/back/methods/ticket-request/deny.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index cdf15c674..afa349684 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -133,6 +133,7 @@ "reserved": "reservado", "Changed sale reserved state": "He cambiado el estado reservado de las siguientes lineas al ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Bought units from buy request": "Se ha comprado {{quantity}} unidades de [{{itemId}} {{concept}}]({{{urlItem}}}) para el ticket id [{{ticketId}}]({{{url}}})", + "Deny buy request":"Se ha rechazado la petición de compra para el ticket id [{{ticketId}}]({{{url}}}). Motivo: {{observation}}", "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} ({{clientId}})]({{{url}}}) a *{{credit}} €*", "Changed client 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}}})", diff --git a/modules/ticket/back/methods/ticket-request/deny.js b/modules/ticket/back/methods/ticket-request/deny.js index 5b79a57cb..6d7df32aa 100644 --- a/modules/ticket/back/methods/ticket-request/deny.js +++ b/modules/ticket/back/methods/ticket-request/deny.js @@ -24,6 +24,8 @@ module.exports = Self => { }); Self.deny = async(ctx, options) => { + const models = Self.app.models; + const $t = ctx.req.__; // $translate const myOptions = {}; let tx; @@ -48,6 +50,20 @@ module.exports = Self => { const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions); await request.updateAttributes(params, myOptions); + // const salesPerson = ticket.client().salesPersonUser(); + // if (salesPerson) { + // const origin = ctx.req.headers.origin; + const origin = ctx.req.headers.origin; + + const message = $t('Deny buy request', { + ticketId: request.ticketFk, + url: `${origin}/#!/ticket/${request.ticketFk}/request/index`, + observation: params.response + }); + // await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message, myOptions); + await models.Chat.send(ctx, '@vicent', message, myOptions); + // } + if (tx) await tx.commit(); return request; From f60fa5a852be9ed8b0ace63897b4cfec122aa25c Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 27 Oct 2021 12:22:32 +0200 Subject: [PATCH 2/7] change receiver to requesterId --- modules/ticket/back/methods/ticket-request/deny.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/deny.js b/modules/ticket/back/methods/ticket-request/deny.js index 6d7df32aa..35de765d7 100644 --- a/modules/ticket/back/methods/ticket-request/deny.js +++ b/modules/ticket/back/methods/ticket-request/deny.js @@ -50,19 +50,16 @@ module.exports = Self => { const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions); await request.updateAttributes(params, myOptions); - // const salesPerson = ticket.client().salesPersonUser(); - // if (salesPerson) { - // const origin = ctx.req.headers.origin; const origin = ctx.req.headers.origin; + const requesterId = request.requesterFk; const message = $t('Deny buy request', { ticketId: request.ticketFk, url: `${origin}/#!/ticket/${request.ticketFk}/request/index`, observation: params.response }); - // await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message, myOptions); - await models.Chat.send(ctx, '@vicent', message, myOptions); - // } + + await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions); if (tx) await tx.commit(); From b1b6d93c8e5228680b2cd97ab6bde1c97e496e75 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 27 Oct 2021 13:39:38 +0200 Subject: [PATCH 3/7] change column value : checkbox for text --- modules/ticket/front/request/index/index.html | 12 ++++-------- modules/ticket/front/request/index/locale/es.yml | 5 ++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/ticket/front/request/index/index.html b/modules/ticket/front/request/index/index.html index 39a290d8c..71c8d88ce 100644 --- a/modules/ticket/front/request/index/index.html +++ b/modules/ticket/front/request/index/index.html @@ -25,7 +25,7 @@ Quantity Price Item id - Ok + State @@ -78,13 +78,9 @@ {{::request.saleFk | zeroFill:6}} - - - + + {{$ctrl.getRequestState(request.isOk)}} Date: Wed, 27 Oct 2021 13:41:59 +0200 Subject: [PATCH 4/7] test --- modules/ticket/front/request/index/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/request/index/index.html b/modules/ticket/front/request/index/index.html index 71c8d88ce..054f0c76a 100644 --- a/modules/ticket/front/request/index/index.html +++ b/modules/ticket/front/request/index/index.html @@ -89,7 +89,7 @@ ng-click="$ctrl.removeLine($index)" vn-tooltip="Remove request" tabindex="-1"> - + From 0849f40df7737f2d9e65de7e44663c1ffa74a359 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 10 Nov 2021 11:44:29 +0100 Subject: [PATCH 5/7] feat: update backTest --- .../back/methods/ticket-request/specs/deny.spec.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js index 523c5f065..95fd0e84d 100644 --- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js @@ -1,13 +1,23 @@ const models = require('vn-loopback/server/server').models; describe('ticket-request deny()', () => { - it('should return the dinied ticket request', async() => { + it('should return the denied ticket request', async() => { const tx = await models.TicketRequest.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {id: 4, observation: 'my observation'}}; + const ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + }, + args: {id: 4, observation: 'my observation'}, + }; + + ctx.req.__ = value => { + return value; + }; const result = await models.TicketRequest.deny(ctx, options); From 9b46b310108c54fb062cc0dc34eee6c1924628b8 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 10 Nov 2021 12:03:53 +0100 Subject: [PATCH 6/7] translate --- loopback/locale/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 8890e911f..c4226a2c8 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -117,5 +117,6 @@ "INACTIVE_PROVIDER": "Inactive provider", "reference duplicated": "reference duplicated", "The PDF document does not exists": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option", - "This item is not available": "This item is not available" + "This item is not available": "This item is not available", + "Deny buy request": "Deny buy request" } \ No newline at end of file From 095e137c06189200fd9fbd25dd98465b70f95b30 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 15 Nov 2021 10:10:57 +0100 Subject: [PATCH 7/7] translate to english --- loopback/locale/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index c4226a2c8..271c3fd4f 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -118,5 +118,5 @@ "reference duplicated": "reference duplicated", "The PDF document does not exists": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option", "This item is not available": "This item is not available", - "Deny buy request": "Deny buy request" + "Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}" } \ No newline at end of file