From a32ebc37da812b203be96817f9766c01ae31ce35 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 9 Mar 2022 23:54:23 +0100 Subject: [PATCH 01/15] add supplier autonomous --- db/changes/10430-ash/00-aclAgency.sql | 2 + .../10430-ash/00-aclSupplierAgencyTerms.sql | 3 + .../10430-ash/00-supplierAgencyTerm.sql | 27 ++++++ db/dump/fixtures.sql | 8 ++ loopback/locale/es.json | 3 +- modules/supplier/back/model-config.json | 3 + .../back/models/supplier-agency-term.js | 9 ++ .../back/models/supplier-agency-term.json | 47 ++++++++++ modules/supplier/front/agency-term/index.html | 85 +++++++++++++++++++ modules/supplier/front/agency-term/index.js | 28 ++++++ .../supplier/front/agency-term/index.spec.js | 34 ++++++++ .../supplier/front/agency-term/locale/es.yml | 8 ++ modules/supplier/front/index.js | 1 + modules/supplier/front/routes.json | 8 ++ 14 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 db/changes/10430-ash/00-aclAgency.sql create mode 100644 db/changes/10430-ash/00-aclSupplierAgencyTerms.sql create mode 100644 db/changes/10430-ash/00-supplierAgencyTerm.sql create mode 100644 modules/supplier/back/models/supplier-agency-term.js create mode 100644 modules/supplier/back/models/supplier-agency-term.json create mode 100644 modules/supplier/front/agency-term/index.html create mode 100644 modules/supplier/front/agency-term/index.js create mode 100644 modules/supplier/front/agency-term/index.spec.js create mode 100644 modules/supplier/front/agency-term/locale/es.yml diff --git a/db/changes/10430-ash/00-aclAgency.sql b/db/changes/10430-ash/00-aclAgency.sql new file mode 100644 index 000000000..8073ee69c --- /dev/null +++ b/db/changes/10430-ash/00-aclAgency.sql @@ -0,0 +1,2 @@ +INSERT INTO salix.ACL (id, model, property, accessType, permission, principalType, principalId) + VALUES(304, 'Agency', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql b/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql new file mode 100644 index 000000000..fbeaa4447 --- /dev/null +++ b/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES + ('SupplierAgencyTerms', '*', '*', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/changes/10430-ash/00-supplierAgencyTerm.sql b/db/changes/10430-ash/00-supplierAgencyTerm.sql new file mode 100644 index 000000000..351efd143 --- /dev/null +++ b/db/changes/10430-ash/00-supplierAgencyTerm.sql @@ -0,0 +1,27 @@ +ALTER TABLE vn.agencyTerm ADD supplierFk INT NULL; +ALTER TABLE vn.agencyTerm CHANGE supplierFk supplierFk INT NULL AFTER agencyFk; + +UPDATE vn.agencyTerm `at` + JOIN vn.agency a ON a.id = `at`.agencyFk +SET `at`.supplierFk = a.supplierFk; + +ALTER TABLE vn.agencyTerm ADD CONSTRAINT agencyTerm_FK FOREIGN KEY (agencyFk) REFERENCES vn.agency(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.agencyTerm ADD CONSTRAINT agencyTerm_FK_1 FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON DELETE RESTRICT ON UPDATE CASCADE; + +RENAME TABLE vn.agencyTerm TO vn.supplierAgencyTerm; + +CREATE OR REPLACE +ALGORITHM = UNDEFINED +DEFINER=`root`@`localhost` +VIEW `vn`.`agencyTerm` AS +SELECT + `sat`.`agencyFk` AS `agencyFk`, + `sat`.`minimumPackages` AS `minimumPackages`, + `sat`.`kmPrice` AS `kmPrice`, + `sat`.`packagePrice` AS `packagePrice`, + `sat`.`routePrice` AS `routePrice`, + `sat`.`minimumKm` AS `minimumKm`, + `sat`.`minimumM3` AS `minimumM3`, + `sat`.`m3Price` AS `m3Price` +FROM + `vn`.`supplierAgencyTerm` `sat` diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index edb937e5f..50a12a094 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2472,3 +2472,11 @@ INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`) INSERT INTO `vn`.`docuwareConfig` (`url`) VALUES ('https://verdnatura.docuware.cloud/docuware/platform'); + +INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackages`, `kmPrice`, `packagePrice`, `routePrice`, `minimumKm`, `minimumM3`, `m3Price`) + VALUES + (1, 1, 0, 0.00, 0.00, NULL, 0, 0.00, 23), + (2, 1, 60, 0.00, 0.00, NULL, 0, 5.00, 33), + (3, 2, 0, 15.00, 0.00, NULL, 0, 0.00, 0), + (4, 2, 0, 20.00, 0.00, NULL, 0, 0.00, 0), + (5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 856ee57d8..aa86e8ab6 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -219,5 +219,6 @@ "You can not modify is pay method checked": "No se puede modificar el campo método de pago validado", "Can't transfer claimed sales": "No puedes transferir lineas reclamadas", "You don't have privileges to create pay back": "No tienes permisos para crear un abono", - "The item is required": "El artículo es requerido" + "The item is required": "El artículo es requerido", + "The agency is already assigned to another autonomous": "La agencia ya está asignada a otro autónomo" } \ No newline at end of file diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json index 7febc17b4..7c1bba1ec 100644 --- a/modules/supplier/back/model-config.json +++ b/modules/supplier/back/model-config.json @@ -11,6 +11,9 @@ "SupplierAccount": { "dataSource": "vn" }, + "SupplierAgencyTerm": { + "dataSource": "vn" + }, "SupplierLog": { "dataSource": "vn" }, diff --git a/modules/supplier/back/models/supplier-agency-term.js b/modules/supplier/back/models/supplier-agency-term.js new file mode 100644 index 000000000..93cee928b --- /dev/null +++ b/modules/supplier/back/models/supplier-agency-term.js @@ -0,0 +1,9 @@ +let UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError(`The agency is already assigned to another autonomous`); + return err; + }); +}; diff --git a/modules/supplier/back/models/supplier-agency-term.json b/modules/supplier/back/models/supplier-agency-term.json new file mode 100644 index 000000000..dff4c9e8b --- /dev/null +++ b/modules/supplier/back/models/supplier-agency-term.json @@ -0,0 +1,47 @@ +{ + "name": "SupplierAgencyTerm", + "base": "VnModel", + "options": { + "mysql": { + "table": "supplierAgencyTerm" + } + }, + "properties": { + "agencyFk": { + "type": "number", + "id": true + }, + "supplierFk": { + "type": "number" + }, + "minimumPackages": { + "type": "number" + }, + "kmPrice": { + "type": "number" + }, + "packagePrice": { + "type": "number" + }, + "routePrice": { + "type": "number" + }, + "minimumKm": { + "type": "number" + }, + "minimumM3": { + "type": "number" + }, + "m3Price": { + "type": "number" + } + }, + "acls": [ + { + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/supplier/front/agency-term/index.html b/modules/supplier/front/agency-term/index.html new file mode 100644 index 000000000..5e61e311c --- /dev/null +++ b/modules/supplier/front/agency-term/index.html @@ -0,0 +1,85 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/modules/supplier/front/agency-term/index.js b/modules/supplier/front/agency-term/index.js new file mode 100644 index 000000000..75eda0223 --- /dev/null +++ b/modules/supplier/front/agency-term/index.js @@ -0,0 +1,28 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +class Controller extends Section { + constructor($element, $) { + super($element, $); + } + + add() { + this.$.model.insert({}); + } + + onSubmit() { + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + }); + } +} + +ngModule.vnComponent('vnSupplierAgencyTerm', { + template: require('./index.html'), + controller: Controller, + bindings: { + supplier: '<' + } +}); diff --git a/modules/supplier/front/agency-term/index.spec.js b/modules/supplier/front/agency-term/index.spec.js new file mode 100644 index 000000000..8b4b8596b --- /dev/null +++ b/modules/supplier/front/agency-term/index.spec.js @@ -0,0 +1,34 @@ +import './index.js'; +import crudModel from 'core/mocks/crud-model'; + +describe('Item', () => { + describe('Component vnItemTags', () => { + let $scope; + let controller; + + beforeEach(ngModule('item')); + + beforeEach(inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + $scope.model = crudModel; + const $element = angular.element(''); + controller = $componentController('vnItemTags', {$element, $scope}); + })); + + describe('getHighestPriority', () => { + it('should return the highest priority value + 1 from the array', () => { + $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}]; + let result = controller.getHighestPriority(); + + expect(result).toEqual(3); + }); + + it('should return 1 when there is no priority defined', () => { + $scope.model.data = []; + let result = controller.getHighestPriority(); + + expect(result).toEqual(1); + }); + }); + }); +}); diff --git a/modules/supplier/front/agency-term/locale/es.yml b/modules/supplier/front/agency-term/locale/es.yml new file mode 100644 index 000000000..f4ba7d87d --- /dev/null +++ b/modules/supplier/front/agency-term/locale/es.yml @@ -0,0 +1,8 @@ +Minimum M3: M3 minimos +Package Price: Precio bulto +Km Price: Precio Km +M3 Price: Precio M3 +Route Price: Precio ruta +Minimum Km: Km minimos +Remove row: Eliminar fila +Add row: Añadir fila \ No newline at end of file diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index dc131ef4a..e52db0675 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -18,3 +18,4 @@ import './billing-data'; import './address/index'; import './address/create'; import './address/edit'; +import './agency-term'; diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 3d3814f5d..16376e37c 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -15,6 +15,7 @@ {"state": "supplier.card.address.index", "icon": "icon-delivery"}, {"state": "supplier.card.account", "icon": "icon-account"}, {"state": "supplier.card.contact", "icon": "contact_phone"}, + {"state": "supplier.card.agencyTerm", "icon": "contact_support"}, {"state": "supplier.card.log", "icon": "history"}, {"state": "supplier.card.consumption", "icon": "show_chart"} ] @@ -86,6 +87,13 @@ "supplier": "$ctrl.supplier" } }, + { + "url": "/agency-term", + "state": "supplier.card.agencyTerm", + "component": "vn-supplier-agency-term", + "description": "Autonomous", + "acl": ["administrative"] + }, { "url": "/consumption?q", "state": "supplier.card.consumption", From 189fe2ed41fc6e0dc8b424ca182b6b152baa89d4 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 10 Mar 2022 08:14:50 +0100 Subject: [PATCH 02/15] update acl --- db/changes/10430-ash/00-aclSupplierAgencyTerms.sql | 2 +- modules/supplier/front/agency-term/index.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql b/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql index fbeaa4447..a762f0e64 100644 --- a/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql +++ b/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql @@ -1,3 +1,3 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) VALUES - ('SupplierAgencyTerms', '*', '*', 'ALLOW', 'ROLE', 'administrative'); + ('SupplierAgencyTerm', '*', '*', 'ALLOW', 'ROLE', 'administrative'); diff --git a/modules/supplier/front/agency-term/index.js b/modules/supplier/front/agency-term/index.js index 75eda0223..bfdf58d50 100644 --- a/modules/supplier/front/agency-term/index.js +++ b/modules/supplier/front/agency-term/index.js @@ -2,10 +2,6 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { - constructor($element, $) { - super($element, $); - } - add() { this.$.model.insert({}); } From 16208a5e115fdd976cf2a08c09a112dfbc5d4872 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 10 Mar 2022 10:35:35 +0100 Subject: [PATCH 03/15] especify PK --- modules/supplier/front/agency-term/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/supplier/front/agency-term/index.html b/modules/supplier/front/agency-term/index.html index 5e61e311c..d58c55528 100644 --- a/modules/supplier/front/agency-term/index.html +++ b/modules/supplier/front/agency-term/index.html @@ -2,6 +2,7 @@ vn-id="model" url="SupplierAgencyTerms" link="{supplierFk: $ctrl.$params.id}" + primary-key="agencyFk" data="$ctrl.supplierAgencyTerms" auto-load="true"> @@ -10,7 +11,7 @@ data="$ctrl.supplierAgencyTerms" form="form"> -
+ Date: Thu, 10 Mar 2022 10:40:52 +0100 Subject: [PATCH 04/15] delete frontTest --- .../supplier/front/agency-term/index.spec.js | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 modules/supplier/front/agency-term/index.spec.js diff --git a/modules/supplier/front/agency-term/index.spec.js b/modules/supplier/front/agency-term/index.spec.js deleted file mode 100644 index 8b4b8596b..000000000 --- a/modules/supplier/front/agency-term/index.spec.js +++ /dev/null @@ -1,34 +0,0 @@ -import './index.js'; -import crudModel from 'core/mocks/crud-model'; - -describe('Item', () => { - describe('Component vnItemTags', () => { - let $scope; - let controller; - - beforeEach(ngModule('item')); - - beforeEach(inject(($componentController, $rootScope) => { - $scope = $rootScope.$new(); - $scope.model = crudModel; - const $element = angular.element(''); - controller = $componentController('vnItemTags', {$element, $scope}); - })); - - describe('getHighestPriority', () => { - it('should return the highest priority value + 1 from the array', () => { - $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}]; - let result = controller.getHighestPriority(); - - expect(result).toEqual(3); - }); - - it('should return 1 when there is no priority defined', () => { - $scope.model.data = []; - let result = controller.getHighestPriority(); - - expect(result).toEqual(1); - }); - }); - }); -}); From ec4112377276d5b1b1ec3486c8ff0a332f21aec3 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 15 Mar 2022 09:36:48 +0100 Subject: [PATCH 05/15] button for insert rows --- .../front/agency-term/create/index.html | 75 +++++++++++++ .../front/agency-term/create/index.js | 34 ++++++ .../front/agency-term/create/index.spec.js | 102 ++++++++++++++++++ .../front/agency-term/{ => index}/index.html | 12 ++- .../front/agency-term/{ => index}/index.js | 4 +- modules/supplier/front/index.js | 3 +- modules/supplier/front/routes.json | 23 +++- modules/zone/back/models/agency.json | 7 ++ 8 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 modules/supplier/front/agency-term/create/index.html create mode 100644 modules/supplier/front/agency-term/create/index.js create mode 100644 modules/supplier/front/agency-term/create/index.spec.js rename modules/supplier/front/agency-term/{ => index}/index.html (92%) rename modules/supplier/front/agency-term/{ => index}/index.js (83%) diff --git a/modules/supplier/front/agency-term/create/index.html b/modules/supplier/front/agency-term/create/index.html new file mode 100644 index 000000000..5d0dca4ef --- /dev/null +++ b/modules/supplier/front/agency-term/create/index.html @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/supplier/front/agency-term/create/index.js b/modules/supplier/front/agency-term/create/index.js new file mode 100644 index 000000000..f876f9003 --- /dev/null +++ b/modules/supplier/front/agency-term/create/index.js @@ -0,0 +1,34 @@ +import ngModule from '../../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + + this.filter = { + fields: [ + 'name' + ], + include: [{ + relation: 'supplierAgencyTerm', + where: { + supplierFk: 1 + } + }], + }; + } + + onSubmit() { + this.$.watcher.submit().then(res => { + this.$state.go('supplier.card.address.index'); + }); + } +} + +ngModule.vnComponent('vnSupplierAgencyTermCreate', { + template: require('./index.html'), + controller: Controller, + bindings: { + supplier: '<' + } +}); diff --git a/modules/supplier/front/agency-term/create/index.spec.js b/modules/supplier/front/agency-term/create/index.spec.js new file mode 100644 index 000000000..026de3769 --- /dev/null +++ b/modules/supplier/front/agency-term/create/index.spec.js @@ -0,0 +1,102 @@ +import './index'; +import watcher from 'core/mocks/watcher'; + +describe('Supplier', () => { + describe('Component vnSupplierAddressCreate', () => { + let $scope; + let controller; + let $element; + let $state; + + beforeEach(ngModule('supplier')); + + beforeEach(inject(($componentController, $rootScope, _$state_) => { + $scope = $rootScope.$new(); + $state = _$state_; + $state.params.id = '1234'; + $element = angular.element(''); + controller = $componentController('vnSupplierAddressCreate', {$element, $scope}); + controller.$.watcher = watcher; + controller.$.watcher.submit = () => { + return { + then: callback => { + callback({data: {id: 124}}); + } + }; + }; + controller.supplier = {id: 1}; + })); + + describe('onSubmit()', () => { + it('should perform a PATCH and then redirect to the main section', () => { + jest.spyOn(controller.$state, 'go'); + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.address.index'); + }); + }); + + describe('town() setter', () => { + it(`should set provinceFk property`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [] + }; + + expect(controller.address.provinceFk).toEqual(1); + }); + + it(`should set provinceFk property and fill the postalCode if there's just one`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [{code: '46001'}] + }; + + expect(controller.address.provinceFk).toEqual(1); + expect(controller.address.postalCode).toEqual('46001'); + }); + }); + + describe('postcode() setter', () => { + it(`should set the town and province properties`, () => { + controller.postcode = { + townFk: 1, + code: 46001, + town: { + id: 1, + name: 'New York', + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + } + } + }; + + expect(controller.address.city).toEqual('New York'); + expect(controller.address.provinceFk).toEqual(1); + }); + }); + }); +}); diff --git a/modules/supplier/front/agency-term/index.html b/modules/supplier/front/agency-term/index/index.html similarity index 92% rename from modules/supplier/front/agency-term/index.html rename to modules/supplier/front/agency-term/index/index.html index d58c55528..b472aaf91 100644 --- a/modules/supplier/front/agency-term/index.html +++ b/modules/supplier/front/agency-term/index/index.html @@ -15,7 +15,7 @@ - \ No newline at end of file + + + diff --git a/modules/supplier/front/agency-term/index.js b/modules/supplier/front/agency-term/index/index.js similarity index 83% rename from modules/supplier/front/agency-term/index.js rename to modules/supplier/front/agency-term/index/index.js index bfdf58d50..416440ef5 100644 --- a/modules/supplier/front/agency-term/index.js +++ b/modules/supplier/front/agency-term/index/index.js @@ -1,4 +1,4 @@ -import ngModule from '../module'; +import ngModule from '../../module'; import Section from 'salix/components/section'; class Controller extends Section { @@ -15,7 +15,7 @@ class Controller extends Section { } } -ngModule.vnComponent('vnSupplierAgencyTerm', { +ngModule.vnComponent('vnSupplierAgencyTermIndex', { template: require('./index.html'), controller: Controller, bindings: { diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index e52db0675..ba2768854 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -18,4 +18,5 @@ import './billing-data'; import './address/index'; import './address/create'; import './address/edit'; -import './agency-term'; +import './agency-term/index'; +import './agency-term/create'; diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 16376e37c..39445e5a1 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -15,7 +15,7 @@ {"state": "supplier.card.address.index", "icon": "icon-delivery"}, {"state": "supplier.card.account", "icon": "icon-account"}, {"state": "supplier.card.contact", "icon": "contact_phone"}, - {"state": "supplier.card.agencyTerm", "icon": "contact_support"}, + {"state": "supplier.card.agencyTerm.index", "icon": "contact_support"}, {"state": "supplier.card.log", "icon": "history"}, {"state": "supplier.card.consumption", "icon": "show_chart"} ] @@ -90,9 +90,26 @@ { "url": "/agency-term", "state": "supplier.card.agencyTerm", - "component": "vn-supplier-agency-term", + "component": "ui-view", + "abstract": true + }, + { + "url": "/index?q", + "state": "supplier.card.agencyTerm.index", + "component": "vn-supplier-agency-term-index", "description": "Autonomous", - "acl": ["administrative"] + "params": { + "supplier": "$ctrl.supplier" + } + }, + { + "url": "/create", + "state": "supplier.card.agencyTerm.create", + "component": "vn-supplier-agency-term-create", + "description": "New autonomous", + "params": { + "supplier": "$ctrl.supplier" + } }, { "url": "/consumption?q", diff --git a/modules/zone/back/models/agency.json b/modules/zone/back/models/agency.json index edec36f87..699b60e79 100644 --- a/modules/zone/back/models/agency.json +++ b/modules/zone/back/models/agency.json @@ -16,5 +16,12 @@ "type": "string", "required": false } + }, + "relations": { + "supplierAgencyTerm": { + "type": "belongsTo", + "model": "SupplierAgencyTerm", + "foreignKey": "agencyFk" + } } } From 1ecc76067a2dd3d21886476d5fc8e50f713160e4 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 15 Mar 2022 14:50:09 +0100 Subject: [PATCH 06/15] code to correct insert in model --- .../front/agency-term/create/index.html | 4 +-- .../front/agency-term/create/index.js | 29 ++++++++++++------- .../front/agency-term/index/index.html | 8 ----- modules/zone/back/models/agency.json | 2 +- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/modules/supplier/front/agency-term/create/index.html b/modules/supplier/front/agency-term/create/index.html index 5d0dca4ef..f224edc0e 100644 --- a/modules/supplier/front/agency-term/create/index.html +++ b/modules/supplier/front/agency-term/create/index.html @@ -10,7 +10,7 @@ auto-load="true" url="Agencies" filter="$ctrl.filter" - data="agencies"> + data="$ctrl.agencies">
@@ -18,7 +18,7 @@ diff --git a/modules/supplier/front/agency-term/create/index.js b/modules/supplier/front/agency-term/create/index.js index f876f9003..efd5f913d 100644 --- a/modules/supplier/front/agency-term/create/index.js +++ b/modules/supplier/front/agency-term/create/index.js @@ -5,22 +5,29 @@ export default class Controller extends Section { constructor($element, $) { super($element, $); - this.filter = { - fields: [ - 'name' - ], - include: [{ - relation: 'supplierAgencyTerm', - where: { - supplierFk: 1 - } - }], + this.supplierAgencyTerm = { + supplierFk: this.$params.id }; + + this.filter = { + include: { + relation: 'supplierAgencyTerm', + scope: { + where: { + supplierFk: 1 + } + } + } + }; + } + + $onInit() { + console.log(this); } onSubmit() { this.$.watcher.submit().then(res => { - this.$state.go('supplier.card.address.index'); + this.$state.go('supplier.card.agencyTerm.index'); }); } } diff --git a/modules/supplier/front/agency-term/index/index.html b/modules/supplier/front/agency-term/index/index.html index b472aaf91..835de5cbf 100644 --- a/modules/supplier/front/agency-term/index/index.html +++ b/modules/supplier/front/agency-term/index/index.html @@ -68,14 +68,6 @@ - - - - Date: Thu, 17 Mar 2022 14:27:55 +0100 Subject: [PATCH 07/15] add new row --- db/dump/fixtures.sql | 8 +--- .../back/methods/supplier/freeAgencies.js | 42 +++++++++++++++++++ .../back/models/supplier-agency-term.json | 7 ++++ modules/supplier/back/models/supplier.js | 1 + .../front/agency-term/create/index.html | 5 +-- .../front/agency-term/create/index.js | 15 ------- .../front/agency-term/index/index.html | 11 +++-- .../supplier/front/agency-term/index/index.js | 12 ++++++ 8 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 modules/supplier/back/methods/supplier/freeAgencies.js diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index d87dc046a..f798d4284 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2457,12 +2457,6 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (1107, 500, CURDATE(), CURDATE()), (1109, 500, CURDATE(), CURDATE()); -INSERT INTO `vn`.`agencyTerm` (`agencyFk`, `minimumPackages`, `kmPrice`, `packagePrice`, `routePrice`, `minimumKm`, `minimumM3`, `m3Price`) - VALUES - (1, 0, 0.00, 0.00, NULL, 0, 0.00, 0), - (3, 0, 0.00, 3.05, NULL, 0, 0.00, 0), - (2, 60, 0.00, 0.00, NULL, 0, 5.00, 33); - UPDATE `vn`.`agency` SET `supplierFk`=1 WHERE `id`=1; @@ -2505,4 +2499,4 @@ INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackage (2, 1, 60, 0.00, 0.00, NULL, 0, 5.00, 33), (3, 2, 0, 15.00, 0.00, NULL, 0, 0.00, 0), (4, 2, 0, 20.00, 0.00, NULL, 0, 0.00, 0), - (5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0); + (5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0); diff --git a/modules/supplier/back/methods/supplier/freeAgencies.js b/modules/supplier/back/methods/supplier/freeAgencies.js new file mode 100644 index 000000000..48c027e4e --- /dev/null +++ b/modules/supplier/back/methods/supplier/freeAgencies.js @@ -0,0 +1,42 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethod('freeAgencies', { + description: 'Returns a list of agencies without a supplier assigned', + accepts: [{ + arg: 'filter', + type: 'object', + description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string` + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/freeAgencies`, + verb: 'GET' + } + }); + + Self.freeAgencies = async(filter, options) => { + const conn = Self.dataSource.connector; + const where = {'sat.supplierFk': null}; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + filter = mergeFilters(filter, {where}); + + let stmt = new ParameterizedSQL( + `SELECT a.name, a.id + FROM agency a + LEFT JOIN supplierAgencyTerm sat ON sat.agencyFk = a.id`, + null, myOptions); + + stmt.merge(conn.makeSuffix(filter)); + + return conn.executeStmt(stmt); + }; +}; diff --git a/modules/supplier/back/models/supplier-agency-term.json b/modules/supplier/back/models/supplier-agency-term.json index dff4c9e8b..0cd7a0891 100644 --- a/modules/supplier/back/models/supplier-agency-term.json +++ b/modules/supplier/back/models/supplier-agency-term.json @@ -36,6 +36,13 @@ "type": "number" } }, + "relations": { + "agency": { + "type": "belongsTo", + "model": "Agency", + "foreignKey": "agencyFk" + } + }, "acls": [ { "accessType": "EXECUTE", diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index f8b096b30..c1be3488f 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -7,6 +7,7 @@ module.exports = Self => { require('../methods/supplier/getSummary')(Self); require('../methods/supplier/updateFiscalData')(Self); require('../methods/supplier/consumption')(Self); + require('../methods/supplier/freeAgencies')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' diff --git a/modules/supplier/front/agency-term/create/index.html b/modules/supplier/front/agency-term/create/index.html index f224edc0e..e43f6396a 100644 --- a/modules/supplier/front/agency-term/create/index.html +++ b/modules/supplier/front/agency-term/create/index.html @@ -8,14 +8,13 @@ - @@ -14,15 +15,13 @@ - - + Date: Thu, 17 Mar 2022 14:51:49 +0100 Subject: [PATCH 08/15] add frontTest --- .../front/agency-term/create/index.spec.js | 84 ++----------------- .../front/agency-term/index/index.spec.js | 37 ++++++++ 2 files changed, 42 insertions(+), 79 deletions(-) create mode 100644 modules/supplier/front/agency-term/index/index.spec.js diff --git a/modules/supplier/front/agency-term/create/index.spec.js b/modules/supplier/front/agency-term/create/index.spec.js index 026de3769..682e1cc58 100644 --- a/modules/supplier/front/agency-term/create/index.spec.js +++ b/modules/supplier/front/agency-term/create/index.spec.js @@ -6,96 +6,22 @@ describe('Supplier', () => { let $scope; let controller; let $element; - let $state; beforeEach(ngModule('supplier')); beforeEach(inject(($componentController, $rootScope, _$state_) => { $scope = $rootScope.$new(); - $state = _$state_; - $state.params.id = '1234'; - $element = angular.element(''); - controller = $componentController('vnSupplierAddressCreate', {$element, $scope}); - controller.$.watcher = watcher; - controller.$.watcher.submit = () => { - return { - then: callback => { - callback({data: {id: 124}}); - } - }; - }; - controller.supplier = {id: 1}; + $scope.watcher = watcher; + $element = angular.element(''); + controller = $componentController('vnSupplierAgencyTermCreate', {$element, $scope}); })); describe('onSubmit()', () => { - it('should perform a PATCH and then redirect to the main section', () => { + it(`should redirect to 'supplier.card.agencyTerm.index' state`, () => { jest.spyOn(controller.$state, 'go'); controller.onSubmit(); - expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.address.index'); - }); - }); - - describe('town() setter', () => { - it(`should set provinceFk property`, () => { - controller.town = { - provinceFk: 1, - code: 46001, - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - }, - postcodes: [] - }; - - expect(controller.address.provinceFk).toEqual(1); - }); - - it(`should set provinceFk property and fill the postalCode if there's just one`, () => { - controller.town = { - provinceFk: 1, - code: 46001, - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - }, - postcodes: [{code: '46001'}] - }; - - expect(controller.address.provinceFk).toEqual(1); - expect(controller.address.postalCode).toEqual('46001'); - }); - }); - - describe('postcode() setter', () => { - it(`should set the town and province properties`, () => { - controller.postcode = { - townFk: 1, - code: 46001, - town: { - id: 1, - name: 'New York', - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - } - } - }; - - expect(controller.address.city).toEqual('New York'); - expect(controller.address.provinceFk).toEqual(1); + expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.agencyTerm.index'); }); }); }); diff --git a/modules/supplier/front/agency-term/index/index.spec.js b/modules/supplier/front/agency-term/index/index.spec.js new file mode 100644 index 000000000..3e9ea4c1e --- /dev/null +++ b/modules/supplier/front/agency-term/index/index.spec.js @@ -0,0 +1,37 @@ +import './index'; +import watcher from 'core/mocks/watcher'; +import crudModel from 'core/mocks/crud-model'; + +describe('Supplier', () => { + describe('Component vnSupplierAddressCreate', () => { + let $scope; + let controller; + let $element; + + beforeEach(ngModule('supplier')); + + beforeEach(inject(($componentController, $rootScope, _$state_) => { + $scope = $rootScope.$new(); + $scope.model = crudModel; + $scope.watcher = watcher; + $element = angular.element(''); + controller = $componentController('vnSupplierAgencyTermIndex', {$element, $scope}); + })); + + describe('onSubmit()', () => { + it('should make HTTP POST request to save values', () => { + jest.spyOn($scope.watcher, 'check'); + jest.spyOn($scope.watcher, 'notifySaved'); + jest.spyOn($scope.watcher, 'updateOriginalData'); + jest.spyOn($scope.model, 'save'); + + controller.onSubmit(); + + expect($scope.model.save).toHaveBeenCalledWith(); + expect($scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect($scope.watcher.check).toHaveBeenCalledWith(); + expect($scope.watcher.notifySaved).toHaveBeenCalledWith(); + }); + }); + }); +}); From c660786e454284e6d9fe7bd0827c32b05baa73e5 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 17 Mar 2022 14:52:06 +0100 Subject: [PATCH 09/15] refactor chaneg name --- .../10430-ash/{00-agencyTerm.sql => 00-agencyTermConfig.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/10430-ash/{00-agencyTerm.sql => 00-agencyTermConfig.sql} (100%) diff --git a/db/changes/10430-ash/00-agencyTerm.sql b/db/changes/10430-ash/00-agencyTermConfig.sql similarity index 100% rename from db/changes/10430-ash/00-agencyTerm.sql rename to db/changes/10430-ash/00-agencyTermConfig.sql From 894f95cb1fcf95c6aae23f0452327edb8fc23271 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 17 Mar 2022 15:05:13 +0100 Subject: [PATCH 10/15] update consulte sql --- modules/route/back/methods/agency-term/filter.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js index 0bca9ddf7..2b557034d 100644 --- a/modules/route/back/methods/agency-term/filter.js +++ b/modules/route/back/methods/agency-term/filter.js @@ -42,20 +42,20 @@ module.exports = Self => { SUM(t.packages) packages, r.m3, r.kmEnd - r.kmStart kmTotal, - CAST(IFNULL(ate.routePrice, - (ate.kmPrice * (GREATEST(r.kmEnd - r.kmStart , ate.minimumKm)) - + GREATEST(r.m3 , ate.minimumM3) * ate.m3Price) - + ate.packagePrice * SUM(t.packages) ) + CAST(IFNULL(sat.routePrice, + (sat.kmPrice * (GREATEST(r.kmEnd - r.kmStart , sat.minimumKm)) + + GREATEST(r.m3 , sat.minimumM3) * sat.m3Price) + + sat.packagePrice * SUM(t.packages) ) AS DECIMAL(10,2)) price, r.invoiceInFk, - a.supplierFk, + sat.supplierFk, s.name supplierName FROM vn.route r LEFT JOIN vn.agencyMode am ON r.agencyModeFk = am.id LEFT JOIN vn.agency a ON am.agencyFk = a.id LEFT JOIN vn.ticket t ON t.routeFk = r.id - LEFT JOIN vn.agencyTerm ate ON ate.agencyFk = a.id - LEFT JOIN vn.supplier s ON s.id = a.supplierFk + LEFT JOIN vn.supplierAgencyTerm sat ON sat.agencyFk = a.id + LEFT JOIN vn.supplier s ON s.id = sat.supplierFk WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND a.supplierFk IS NOT NULL GROUP BY r.id ) a` From f501d20c65b79f2f15ff2fb9faa95fc779f2d0e6 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 18 Mar 2022 12:41:15 +0100 Subject: [PATCH 11/15] update sql --- .../10430-ash/00-supplierAgencyTerm.sql | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/db/changes/10430-ash/00-supplierAgencyTerm.sql b/db/changes/10430-ash/00-supplierAgencyTerm.sql index 351efd143..4a976b83d 100644 --- a/db/changes/10430-ash/00-supplierAgencyTerm.sql +++ b/db/changes/10430-ash/00-supplierAgencyTerm.sql @@ -24,4 +24,25 @@ SELECT `sat`.`minimumM3` AS `minimumM3`, `sat`.`m3Price` AS `m3Price` FROM - `vn`.`supplierAgencyTerm` `sat` + `vn`.`supplierAgencyTerm` `sat`; + +ALTER TABLE vn.agency DROP FOREIGN KEY agency_ibfk_4; +ALTER TABLE vn.agency CHANGE supplierFk supplierFk__ int(11) DEFAULT NULL NULL; + +CREATE OR REPLACE +ALGORITHM = UNDEFINED +DEFINER=`root`@`localhost` +VIEW `vn2008`.`agency` AS +SELECT + `a`.`id` AS `agency_id`, + `a`.`name` AS `name`, + `a`.`warehouseFk` AS `warehouse_id`, + `a`.`isVolumetric` AS `por_volumen`, + `a`.`bankFk` AS `Id_Banco`, + `a`.`warehouseAliasFk` AS `warehouse_alias_id`, + `a`.`isOwn` AS `propios`, + `a`.`labelZone` AS `zone_label`, + `a`.`workCenterFk` AS `workCenterFk`, + `a`.`supplierFk__` AS `supplierFk__` +FROM + `vn`.`agency` `a`; \ No newline at end of file From 920bff30c8ce8c5b2da16d4f4e1a029100741d5f Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 21 Mar 2022 12:02:17 +0100 Subject: [PATCH 12/15] modify filter sql --- modules/route/back/methods/agency-term/filter.js | 2 +- modules/route/back/methods/agency-term/specs/filter.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js index 2b557034d..4cd79c2a9 100644 --- a/modules/route/back/methods/agency-term/filter.js +++ b/modules/route/back/methods/agency-term/filter.js @@ -56,7 +56,7 @@ module.exports = Self => { LEFT JOIN vn.ticket t ON t.routeFk = r.id LEFT JOIN vn.supplierAgencyTerm sat ON sat.agencyFk = a.id LEFT JOIN vn.supplier s ON s.id = sat.supplierFk - WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND a.supplierFk IS NOT NULL + WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL GROUP BY r.id ) a` ); diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 69a7f987c..172c84d9b 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -15,7 +15,7 @@ describe('AgencyTerm filter()', () => { const firstAgencyTerm = agencyTerms[0]; expect(firstAgencyTerm.routeFk).toEqual(1); - expect(agencyTerms.length).toEqual(3); + expect(agencyTerms.length).toEqual(5); await tx.rollback(); } catch (e) { From 31a5e191512649b8757f7762076089d8cf00da7f Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 21 Mar 2022 13:19:19 +0100 Subject: [PATCH 13/15] move db changes to correct folder --- db/changes/{10430-ash => 10440-fallas}/00-aclAgency.sql | 0 .../{10430-ash => 10440-fallas}/00-aclSupplierAgencyTerms.sql | 0 db/changes/{10430-ash => 10440-fallas}/00-agencyTermConfig.sql | 0 db/changes/{10430-ash => 10440-fallas}/00-supplierAgencyTerm.sql | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{10430-ash => 10440-fallas}/00-aclAgency.sql (100%) rename db/changes/{10430-ash => 10440-fallas}/00-aclSupplierAgencyTerms.sql (100%) rename db/changes/{10430-ash => 10440-fallas}/00-agencyTermConfig.sql (100%) rename db/changes/{10430-ash => 10440-fallas}/00-supplierAgencyTerm.sql (100%) diff --git a/db/changes/10430-ash/00-aclAgency.sql b/db/changes/10440-fallas/00-aclAgency.sql similarity index 100% rename from db/changes/10430-ash/00-aclAgency.sql rename to db/changes/10440-fallas/00-aclAgency.sql diff --git a/db/changes/10430-ash/00-aclSupplierAgencyTerms.sql b/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql similarity index 100% rename from db/changes/10430-ash/00-aclSupplierAgencyTerms.sql rename to db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql diff --git a/db/changes/10430-ash/00-agencyTermConfig.sql b/db/changes/10440-fallas/00-agencyTermConfig.sql similarity index 100% rename from db/changes/10430-ash/00-agencyTermConfig.sql rename to db/changes/10440-fallas/00-agencyTermConfig.sql diff --git a/db/changes/10430-ash/00-supplierAgencyTerm.sql b/db/changes/10440-fallas/00-supplierAgencyTerm.sql similarity index 100% rename from db/changes/10430-ash/00-supplierAgencyTerm.sql rename to db/changes/10440-fallas/00-supplierAgencyTerm.sql From f4d53c404061f0d13d34df572cd239e64b954a30 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 28 Mar 2022 13:35:36 +0200 Subject: [PATCH 14/15] pull request changes required --- db/changes/10440-fallas/00-aclAgency.sql | 2 +- .../00-aclSupplierAgencyTerms.sql | 2 +- .../10440-fallas/00-supplierAgencyTerm.sql | 20 +++++++++---------- .../back/models/supplier-agency-term.js | 2 +- .../back/models/supplier-agency-term.json | 10 +--------- modules/supplier/front/routes.json | 2 +- 6 files changed, 15 insertions(+), 23 deletions(-) diff --git a/db/changes/10440-fallas/00-aclAgency.sql b/db/changes/10440-fallas/00-aclAgency.sql index 8073ee69c..9e5bb6382 100644 --- a/db/changes/10440-fallas/00-aclAgency.sql +++ b/db/changes/10440-fallas/00-aclAgency.sql @@ -1,2 +1,2 @@ -INSERT INTO salix.ACL (id, model, property, accessType, permission, principalType, principalId) +INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES(304, 'Agency', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql b/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql index a762f0e64..fa57c1d64 100644 --- a/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql +++ b/db/changes/10440-fallas/00-aclSupplierAgencyTerms.sql @@ -1,3 +1,3 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('SupplierAgencyTerm', '*', '*', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/changes/10440-fallas/00-supplierAgencyTerm.sql b/db/changes/10440-fallas/00-supplierAgencyTerm.sql index 4a976b83d..f8539f607 100644 --- a/db/changes/10440-fallas/00-supplierAgencyTerm.sql +++ b/db/changes/10440-fallas/00-supplierAgencyTerm.sql @@ -1,14 +1,14 @@ -ALTER TABLE vn.agencyTerm ADD supplierFk INT NULL; -ALTER TABLE vn.agencyTerm CHANGE supplierFk supplierFk INT NULL AFTER agencyFk; +ALTER TABLE `vn`.`agencyTerm` ADD `supplierFk` INT NULL; +ALTER TABLE `vn`.`agencyTerm` CHANGE `supplierFk` `supplierFk` INT NULL AFTER `agencyFk`; -UPDATE vn.agencyTerm `at` - JOIN vn.agency a ON a.id = `at`.agencyFk -SET `at`.supplierFk = a.supplierFk; +UPDATE `vn`.`agencyTerm` `at` + JOIN `vn`.`agency` `a` ON `a`.`id` = `at`.`agencyFk` +SET `at`.`supplierFk` = `a`.`supplierFk`; -ALTER TABLE vn.agencyTerm ADD CONSTRAINT agencyTerm_FK FOREIGN KEY (agencyFk) REFERENCES vn.agency(id) ON DELETE RESTRICT ON UPDATE CASCADE; -ALTER TABLE vn.agencyTerm ADD CONSTRAINT agencyTerm_FK_1 FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `vn`.`agencyTerm` ADD CONSTRAINT `agencyTerm_FK` FOREIGN KEY (`agencyFk`) REFERENCES `vn`.`agency`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `vn`.`agencyTerm` ADD CONSTRAINT `agencyTerm_FK_1` FOREIGN KEY (`supplierFk`) REFERENCES `vn`.`supplier`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; -RENAME TABLE vn.agencyTerm TO vn.supplierAgencyTerm; +RENAME TABLE `vn`.`agencyTerm` TO `vn`.`supplierAgencyTerm`; CREATE OR REPLACE ALGORITHM = UNDEFINED @@ -26,8 +26,8 @@ SELECT FROM `vn`.`supplierAgencyTerm` `sat`; -ALTER TABLE vn.agency DROP FOREIGN KEY agency_ibfk_4; -ALTER TABLE vn.agency CHANGE supplierFk supplierFk__ int(11) DEFAULT NULL NULL; +ALTER TABLE `vn`.`agency` DROP FOREIGN KEY `agency_ibfk_4`; +ALTER TABLE `vn`.`agency` CHANGE `supplierFk` `supplierFk__` int(11) DEFAULT NULL NULL; CREATE OR REPLACE ALGORITHM = UNDEFINED diff --git a/modules/supplier/back/models/supplier-agency-term.js b/modules/supplier/back/models/supplier-agency-term.js index 93cee928b..961413c18 100644 --- a/modules/supplier/back/models/supplier-agency-term.js +++ b/modules/supplier/back/models/supplier-agency-term.js @@ -1,4 +1,4 @@ -let UserError = require('vn-loopback/util/user-error'); +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.rewriteDbError(function(err) { diff --git a/modules/supplier/back/models/supplier-agency-term.json b/modules/supplier/back/models/supplier-agency-term.json index 0cd7a0891..f9c39729a 100644 --- a/modules/supplier/back/models/supplier-agency-term.json +++ b/modules/supplier/back/models/supplier-agency-term.json @@ -42,13 +42,5 @@ "model": "Agency", "foreignKey": "agencyFk" } - }, - "acls": [ - { - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 39445e5a1..35519b89a 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -94,7 +94,7 @@ "abstract": true }, { - "url": "/index?q", + "url": "/index", "state": "supplier.card.agencyTerm.index", "component": "vn-supplier-agency-term-index", "description": "Autonomous", From b72d26f2149e8278bba2874c2f3702a2f759d337 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 28 Mar 2022 13:40:52 +0200 Subject: [PATCH 15/15] fix: update backTest --- modules/route/back/methods/agency-term/specs/filter.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 6bd8cdb7f..d6c00e585 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -72,7 +72,7 @@ describe('AgencyTerm filter()', () => { const results = await models.AgencyTerm.filter(ctx, options); - expect(results.length).toBe(3); + expect(results.length).toBe(5); await tx.rollback(); } catch (e) {