From 4f68a7d2625287668db4f493343d6426ac725a5d Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 17 Jan 2025 15:36:11 +0100 Subject: [PATCH 1/2] feat: refs #8381 add agencyModeFk to travel thermograph and create AgencyModeIncoming model --- db/routines/vn/views/agencyModeIncoming.sql | 9 +++++++ .../00-agencyIncomingForeign.sql | 6 +++++ .../01-travelThermographAlter.sql | 7 +++++ .../back/methods/travel/saveThermograph.js | 6 +++++ modules/travel/back/model-config.json | 5 +++- .../back/models/agency-mode-incoming.json | 27 +++++++++++++++++++ .../back/models/travel-thermograph.json | 5 ++++ 7 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 db/routines/vn/views/agencyModeIncoming.sql create mode 100644 db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql create mode 100644 db/versions/11411-turquoiseEucalyptus/01-travelThermographAlter.sql create mode 100644 modules/travel/back/models/agency-mode-incoming.json diff --git a/db/routines/vn/views/agencyModeIncoming.sql b/db/routines/vn/views/agencyModeIncoming.sql new file mode 100644 index 000000000..f7f6e595d --- /dev/null +++ b/db/routines/vn/views/agencyModeIncoming.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`vn`@`localhost` +SQL SECURITY DEFINER +VIEW `vn`.`agencyModeIncoming` AS + SELECT + am.id, + am.name + FROM `vn`.`agencyMode` AS am + JOIN `vn`.`agencyIncoming` AS ai + ON am.id = ai.agencyModeFk; diff --git a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql new file mode 100644 index 000000000..bf2c75f2b --- /dev/null +++ b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql @@ -0,0 +1,6 @@ +ALTER TABLE `vn`.`agencyIncoming` + ADD CONSTRAINT `fk_agencyIncoming_agencyMode` + FOREIGN KEY (`agencyModeFk`) + REFERENCES `agencyMode`(`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; diff --git a/db/versions/11411-turquoiseEucalyptus/01-travelThermographAlter.sql b/db/versions/11411-turquoiseEucalyptus/01-travelThermographAlter.sql new file mode 100644 index 000000000..3838f59d7 --- /dev/null +++ b/db/versions/11411-turquoiseEucalyptus/01-travelThermographAlter.sql @@ -0,0 +1,7 @@ +ALTER TABLE `vn`.`travelThermograph` + ADD COLUMN `agencyModeFk` INT(11) NULL AFTER `editorFk`, + ADD CONSTRAINT `travelThermograph_agencyIncoming_fk` + FOREIGN KEY (`agencyModeFk`) + REFERENCES `agencyIncoming`(`agencyModeFk`) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/modules/travel/back/methods/travel/saveThermograph.js b/modules/travel/back/methods/travel/saveThermograph.js index 6f7e1c8bf..2517b0b8c 100644 --- a/modules/travel/back/methods/travel/saveThermograph.js +++ b/modules/travel/back/methods/travel/saveThermograph.js @@ -57,6 +57,10 @@ module.exports = Self => { arg: 'hasFileAttached', type: 'Boolean', description: 'True if has an attached file' + }, { + arg: 'agencyModeFk', + type: 'Number', + description: 'Carrier' }], returns: {type: 'object', root: true}, http: {path: `/:id/saveThermograph`, verb: 'POST'} @@ -76,6 +80,7 @@ module.exports = Self => { reference, description, hasFileAttached, + agencyModeFk, options ) => { const models = Self.app.models; @@ -119,6 +124,7 @@ module.exports = Self => { minTemperature, temperatureFk, warehouseFk: warehouseId, + agencyModeFk, }, myOptions); if (tx) await tx.commit(); diff --git a/modules/travel/back/model-config.json b/modules/travel/back/model-config.json index 952ce0d20..e7a644180 100644 --- a/modules/travel/back/model-config.json +++ b/modules/travel/back/model-config.json @@ -22,5 +22,8 @@ }, "Temperature": { "dataSource": "vn" + }, + "AgencyModeIncoming": { + "dataSource": "vn" } -} \ No newline at end of file +} diff --git a/modules/travel/back/models/agency-mode-incoming.json b/modules/travel/back/models/agency-mode-incoming.json new file mode 100644 index 000000000..efefaf872 --- /dev/null +++ b/modules/travel/back/models/agency-mode-incoming.json @@ -0,0 +1,27 @@ +{ + "name": "AgencyModeIncoming", + "base": "VnModel", + "options": { + "mysql": { + "table": "agencyModeIncoming" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} diff --git a/modules/travel/back/models/travel-thermograph.json b/modules/travel/back/models/travel-thermograph.json index cb0a9b4f8..79b692507 100644 --- a/modules/travel/back/models/travel-thermograph.json +++ b/modules/travel/back/models/travel-thermograph.json @@ -58,6 +58,11 @@ "type": "belongsTo", "model": "Thermograph", "foreignKey": "thermographFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" } } } -- 2.40.1 From a46ec1bc8d34150a19ff02568ad78db6b6c73773 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 21 Jan 2025 08:13:56 +0100 Subject: [PATCH 2/2] feat: refs #8381 add agencyModeFk to thermograph and insert agencyIncoming records --- db/dump/fixtures.before.sql | 5 +++++ .../back/methods/travel/specs/saveThermograph.spec.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 590fe34b6..30c49aafc 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -321,6 +321,11 @@ UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com' UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; +INSERT INTO `vn`.`agencyIncoming`(`agencyModeFk`) + VALUES + (1), + (2); + INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `isIbanRequiredForClients`, `isIbanRequiredForSuppliers`, `hasVerified`) VALUES (1, NULL, 'PayMethod one', 0, 001, 0, 0, 0), diff --git a/modules/travel/back/methods/travel/specs/saveThermograph.spec.js b/modules/travel/back/methods/travel/specs/saveThermograph.spec.js index c2da4234e..0f5f248bf 100644 --- a/modules/travel/back/methods/travel/specs/saveThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/saveThermograph.spec.js @@ -9,6 +9,7 @@ describe('Thermograph saveThermograph()', () => { const maxTemperature = 30; const minTemperature = 10; const temperatureFk = 'COOL'; + const agencyModeFk = 1; let tx; let options; @@ -46,13 +47,16 @@ describe('Thermograph saveThermograph()', () => { null, null, null, - null, options + null, + agencyModeFk, + options ); expect(updatedThermograph.result).toEqual(state); expect(updatedThermograph.maxTemperature).toEqual(maxTemperature); expect(updatedThermograph.minTemperature).toEqual(minTemperature); expect(updatedThermograph.temperatureFk).toEqual(temperatureFk); + expect(updatedThermograph.agencyModeFk).toEqual(agencyModeFk); expect(updatedThermograph.dmsFk).toEqual(dmsFk); }); -- 2.40.1