From d68aacc78ada50dbdfec0f604ac8d390883426ee Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 20 Oct 2020 10:19:12 +0200 Subject: [PATCH 1/2] 2525 - Ticket basic data validate zone --- .../ticket/front/basic-data/step-one/index.js | 28 +++++++++++++++---- modules/zone/back/methods/agency/getLanded.js | 7 +++-- .../back/methods/zone/includingExpired.js | 7 +++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/modules/ticket/front/basic-data/step-one/index.js b/modules/ticket/front/basic-data/step-one/index.js index e7eb30583..e1e74ae3f 100644 --- a/modules/ticket/front/basic-data/step-one/index.js +++ b/modules/ticket/front/basic-data/step-one/index.js @@ -56,8 +56,16 @@ class Controller extends Component { set warehouseId(value) { if (value != this.ticket.warehouseFk) { this.ticket.warehouseFk = value; - this.ticket.agencyModeFk = null; - this.ticket.zoneFk = null; + + this.getShipped({ + landed: this.ticket.landed, + addressFk: this.ticket.addressFk, + agencyModeFk: this.ticket.agencyModeFk, + warehouseFk: value + }).then(() => { + if (this.zoneId == null) + this.ticket.agencyModeFk = null; + }); } } @@ -177,8 +185,8 @@ class Controller extends Component { ); } - let query = `tickets/${this.ticket.id}/priceDifference`; - let params = { + const query = `tickets/${this.ticket.id}/priceDifference`; + const params = { landed: this.ticket.landed, addressId: this.ticket.addressFk, agencyModeId: this.ticket.agencyModeFk, @@ -202,9 +210,13 @@ class Controller extends Component { * Returns a landing date */ getLanded(params) { + const validParams = this.shipped && this.addressId + && this.agencyModeId && this.warehouseId; + if (!validParams) return this.$q.resolve(); + this.ticket.zoneFk = null; const query = `Agencies/getLanded`; - this.$http.get(query, {params}).then(res => { + return this.$http.get(query, {params}).then(res => { if (res.data) { this.ticket.zoneFk = res.data.zoneFk; this.ticket.landed = res.data.landed; @@ -221,9 +233,13 @@ class Controller extends Component { * Returns a shipment date */ getShipped(params) { + const validParams = this.landed && this.addressId + && this.agencyModeId && this.warehouseId; + if (!validParams) return this.$q.resolve(); + this.ticket.zoneFk = null; const query = `Agencies/getShipped`; - this.$http.get(query, {params}).then(res => { + return this.$http.get(query, {params}).then(res => { if (res.data) { this.ticket.zoneFk = res.data.zoneFk; this.ticket.landed = params.landed; diff --git a/modules/zone/back/methods/agency/getLanded.js b/modules/zone/back/methods/agency/getLanded.js index 27ac88327..4505c68dd 100644 --- a/modules/zone/back/methods/agency/getLanded.js +++ b/modules/zone/back/methods/agency/getLanded.js @@ -37,9 +37,12 @@ module.exports = Self => { Self.getLanded = async(ctx, shipped, addressFk, agencyModeFk, warehouseFk) => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; - const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss'); + const roles = await models.Account.getRoles(userId); + const canSeeExpired = roles.filter(role => + role == 'productionBoss' || role == 'administrative' + ); let showExpired = false; - if (isProductionBoss) showExpired = true; + if (canSeeExpired.length) showExpired = true; let stmts = []; stmts.push(new ParameterizedSQL( diff --git a/modules/zone/back/methods/zone/includingExpired.js b/modules/zone/back/methods/zone/includingExpired.js index 6428d5b88..a27d04466 100644 --- a/modules/zone/back/methods/zone/includingExpired.js +++ b/modules/zone/back/methods/zone/includingExpired.js @@ -32,9 +32,12 @@ module.exports = Self => { && where.agencyModeFk && where.warehouseFk; if (filterByAvailability) { - const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss'); + const roles = await models.Account.getRoles(userId); + const canSeeExpired = roles.filter(role => + role == 'productionBoss' || role == 'administrative' + ); let showExpired = false; - if (isProductionBoss) showExpired = true; + if (canSeeExpired.length) showExpired = true; stmt = new ParameterizedSQL(`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [ where.shipped, From 0acb1e649dd6a66b0a60f637680e7e924d2c89df Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 20 Oct 2020 10:29:16 +0200 Subject: [PATCH 2/2] Updated unit test --- modules/ticket/front/basic-data/step-one/index.spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/ticket/front/basic-data/step-one/index.spec.js b/modules/ticket/front/basic-data/step-one/index.spec.js index bd88b88ac..c7d09a7b1 100644 --- a/modules/ticket/front/basic-data/step-one/index.spec.js +++ b/modules/ticket/front/basic-data/step-one/index.spec.js @@ -323,6 +323,7 @@ describe('Ticket', () => { warehouseFk: 1 }; const serializedParams = $httpParamSerializer(params); + controller.ticket.shipped = shipped; $httpBackend.expect('GET', `Agencies/getLanded?${serializedParams}`).respond(200, expectedResult); controller.getLanded(params); @@ -344,6 +345,7 @@ describe('Ticket', () => { warehouseFk: 1 }; const serializedParams = $httpParamSerializer(params); + controller.ticket.landed = landed; $httpBackend.expect('GET', `Agencies/getShipped?${serializedParams}`).respond(200, expectedResult); controller.getShipped(params);