From d85a4da1abafb5a72c766cc27e42e92934b31798 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 6 Nov 2018 13:58:13 +0100 Subject: [PATCH] =?UTF-8?q?Bug=20#783=20al=20abrir=20una=20reclamacion=20n?= =?UTF-8?q?avegar=20a=20ella,=20no=20abrir=20nueva=20pesta=C3=B1a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ticket/src/sale/index.html | 8 ++++++++ client/ticket/src/sale/locale/es.yml | 1 + services/claim/package.json | 4 +--- services/claim/server/model-config.json | 6 ------ .../importToNewRefundTicket.js | 0 .../importToNewRefundTicket.spec.js | 4 ++-- .../common/methods/claim/createFromSales.js | 0 .../common/methods/claim/getSummary.js | 0 .../common/methods/claim/regularizeClaim.js | 0 .../claim/specs/createFromSales.spec.js | 0 .../methods/claim/specs/getSummary.spec.js | 0 .../claim/specs/regularizeClaim.spec.js | 0 .../methods/claim/specs/updateClaim.spec.js | 0 .../common/methods/claim/updateClaim.js | 8 ++++---- .../common/methods/ticket/getSales.js | 19 +++++++++++++++++-- .../methods/ticket/specs/getSales.spec.js | 10 +++++----- .../common/models/claim-beginning.js | 0 .../common/models/claim-beginning.json | 0 .../common/models/claim.js | 0 .../common/models/claim.json | 0 services/loopback/package.json | 1 + services/loopback/server/model-config.json | 6 ++++++ 22 files changed, 45 insertions(+), 22 deletions(-) rename services/{claim => loopback}/common/methods/claim-beginning/importToNewRefundTicket.js (100%) rename services/{claim => loopback}/common/methods/claim-beginning/importToNewRefundTicket.spec.js (96%) rename services/{claim => loopback}/common/methods/claim/createFromSales.js (100%) rename services/{claim => loopback}/common/methods/claim/getSummary.js (100%) rename services/{claim => loopback}/common/methods/claim/regularizeClaim.js (100%) rename services/{claim => loopback}/common/methods/claim/specs/createFromSales.spec.js (100%) rename services/{claim => loopback}/common/methods/claim/specs/getSummary.spec.js (100%) rename services/{claim => loopback}/common/methods/claim/specs/regularizeClaim.spec.js (100%) rename services/{claim => loopback}/common/methods/claim/specs/updateClaim.spec.js (100%) rename services/{claim => loopback}/common/methods/claim/updateClaim.js (90%) rename services/{claim => loopback}/common/models/claim-beginning.js (100%) rename services/{claim => loopback}/common/models/claim-beginning.json (100%) rename services/{claim => loopback}/common/models/claim.js (100%) rename services/{claim => loopback}/common/models/claim.json (100%) diff --git a/client/ticket/src/sale/index.html b/client/ticket/src/sale/index.html index b39c5522e..2bf6cee3d 100644 --- a/client/ticket/src/sale/index.html +++ b/client/ticket/src/sale/index.html @@ -70,6 +70,14 @@ + + + + { let refundTicketSales; let salesInsertedInClaimEnd; - afterAll(async() => { + afterAll(async () => { let promises = []; promises.push(app.models.Ticket.destroyById(ticket.id)); @@ -16,7 +16,7 @@ describe('claimBeginning', () => { }); describe('importToNewRefundTicket()', () => { - it('should create a new ticket with negative sales, save an observation, update the state and insert the negative sales into claimEnd', async() => { + it('should create a new ticket with negative sales, save an observation, update the state and insert the negative sales into claimEnd', async () => { let ctxOfSalesAssistant = {req: {accessToken: {userId: 21}}}; let claimId = 1; ticket = await app.models.ClaimBeginning.importToNewRefundTicket(ctxOfSalesAssistant, claimId); diff --git a/services/claim/common/methods/claim/createFromSales.js b/services/loopback/common/methods/claim/createFromSales.js similarity index 100% rename from services/claim/common/methods/claim/createFromSales.js rename to services/loopback/common/methods/claim/createFromSales.js diff --git a/services/claim/common/methods/claim/getSummary.js b/services/loopback/common/methods/claim/getSummary.js similarity index 100% rename from services/claim/common/methods/claim/getSummary.js rename to services/loopback/common/methods/claim/getSummary.js diff --git a/services/claim/common/methods/claim/regularizeClaim.js b/services/loopback/common/methods/claim/regularizeClaim.js similarity index 100% rename from services/claim/common/methods/claim/regularizeClaim.js rename to services/loopback/common/methods/claim/regularizeClaim.js diff --git a/services/claim/common/methods/claim/specs/createFromSales.spec.js b/services/loopback/common/methods/claim/specs/createFromSales.spec.js similarity index 100% rename from services/claim/common/methods/claim/specs/createFromSales.spec.js rename to services/loopback/common/methods/claim/specs/createFromSales.spec.js diff --git a/services/claim/common/methods/claim/specs/getSummary.spec.js b/services/loopback/common/methods/claim/specs/getSummary.spec.js similarity index 100% rename from services/claim/common/methods/claim/specs/getSummary.spec.js rename to services/loopback/common/methods/claim/specs/getSummary.spec.js diff --git a/services/claim/common/methods/claim/specs/regularizeClaim.spec.js b/services/loopback/common/methods/claim/specs/regularizeClaim.spec.js similarity index 100% rename from services/claim/common/methods/claim/specs/regularizeClaim.spec.js rename to services/loopback/common/methods/claim/specs/regularizeClaim.spec.js diff --git a/services/claim/common/methods/claim/specs/updateClaim.spec.js b/services/loopback/common/methods/claim/specs/updateClaim.spec.js similarity index 100% rename from services/claim/common/methods/claim/specs/updateClaim.spec.js rename to services/loopback/common/methods/claim/specs/updateClaim.spec.js diff --git a/services/claim/common/methods/claim/updateClaim.js b/services/loopback/common/methods/claim/updateClaim.js similarity index 90% rename from services/claim/common/methods/claim/updateClaim.js rename to services/loopback/common/methods/claim/updateClaim.js index f398521ed..9f25727ba 100644 --- a/services/claim/common/methods/claim/updateClaim.js +++ b/services/loopback/common/methods/claim/updateClaim.js @@ -1,6 +1,6 @@ -const UserError = require('vn-loopback/common/helpers').UserError; -var pick = require('object.pick'); -var diff = require('object-diff'); +const UserError = require('../../../common/helpers').UserError; +let pick = require('object.pick'); +let diff = require('object-diff'); module.exports = Self => { Self.remoteMethodCtx('updateClaim', { @@ -23,7 +23,7 @@ module.exports = Self => { } }); - Self.updateClaim = async(ctx, params) => { + Self.updateClaim = async (ctx, params) => { let models = Self.app.models; let isSalesAssistant; let token = ctx.req.accessToken; diff --git a/services/loopback/common/methods/ticket/getSales.js b/services/loopback/common/methods/ticket/getSales.js index 4c5c77d04..25b8aaff3 100644 --- a/services/loopback/common/methods/ticket/getSales.js +++ b/services/loopback/common/methods/ticket/getSales.js @@ -23,9 +23,12 @@ module.exports = Self => { let query = `CALL vn.ticketGetVisibleAvailable(?)`; let [lines] = await Self.rawSql(query, [ticketFk]); let ids = []; + let salesIds = []; - for (line of lines) + for (line of lines) { ids.push(line.itemFk); + salesIds.push(line.id); + } let filter = { fields: ['id', 'name', 'tag5', 'value5', 'tag6', 'value6', 'tag7', 'value7', 'tag8', 'value8', 'tag9', 'value9', 'tag10', 'value10'], @@ -33,12 +36,24 @@ module.exports = Self => { }; let items = await Self.app.models.Item.find(filter); + filter = { + fields: ['claimFk', 'saleFk'], + where: {saleFk: {inq: salesIds}}, + }; + let claims = await Self.app.models.ClaimBeginning.find(filter); + let map = {}; for (item of items) map[item.id] = item; - for (line of lines) + let claimMap = {}; + for (claim of claims) + claimMap[claim.saleFk] = claim; + + for (line of lines) { line.tags = map[line.itemFk]; + line.claim = claimMap[line.id]; + } return lines; }; diff --git a/services/loopback/common/methods/ticket/specs/getSales.spec.js b/services/loopback/common/methods/ticket/specs/getSales.spec.js index c488c3ece..5b3c46c25 100644 --- a/services/loopback/common/methods/ticket/specs/getSales.spec.js +++ b/services/loopback/common/methods/ticket/specs/getSales.spec.js @@ -1,11 +1,11 @@ const app = require(`${servicesDir}/ticket/server/server`); describe('ticket getSales()', () => { - it('should return the sales of a ticket', async() => { - let sales = await app.models.Ticket.getSales(1); + it('should return the sales of a ticket', async () => { + let sales = await app.models.Ticket.getSales(16); - expect(sales.length).toBe(4); - expect(sales[0].item).toBeDefined(); - expect(sales[0].item.tags).toBeDefined(); + expect(sales.length).toEqual(4); + expect(sales[0].tags).toBeDefined(); + expect(sales[1].claim).toBeDefined(); }); }); diff --git a/services/claim/common/models/claim-beginning.js b/services/loopback/common/models/claim-beginning.js similarity index 100% rename from services/claim/common/models/claim-beginning.js rename to services/loopback/common/models/claim-beginning.js diff --git a/services/claim/common/models/claim-beginning.json b/services/loopback/common/models/claim-beginning.json similarity index 100% rename from services/claim/common/models/claim-beginning.json rename to services/loopback/common/models/claim-beginning.json diff --git a/services/claim/common/models/claim.js b/services/loopback/common/models/claim.js similarity index 100% rename from services/claim/common/models/claim.js rename to services/loopback/common/models/claim.js diff --git a/services/claim/common/models/claim.json b/services/loopback/common/models/claim.json similarity index 100% rename from services/claim/common/models/claim.json rename to services/loopback/common/models/claim.json diff --git a/services/loopback/package.json b/services/loopback/package.json index fd8eb71ec..74943249d 100644 --- a/services/loopback/package.json +++ b/services/loopback/package.json @@ -20,6 +20,7 @@ "require-yaml": "0.0.1", "serve-favicon": "^2.0.1", "strong-error-handler": "^2.1.0", + "object-diff": "0.0.4", "object.pick": "^1.3.0" }, "devDependencies": { diff --git a/services/loopback/server/model-config.json b/services/loopback/server/model-config.json index 7c0141494..898e5f12a 100644 --- a/services/loopback/server/model-config.json +++ b/services/loopback/server/model-config.json @@ -15,6 +15,12 @@ "ACL": { "dataSource": "salix" }, + "Claim": { + "dataSource": "vn" + }, + "ClaimBeginning": { + "dataSource": "vn" + }, "FieldAcl": { "dataSource": "salix" },