From 086b7aed4b2e2fcf25db2f5b7ddfbdc7075ec09c Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 24 Dec 2024 10:40:17 +0100 Subject: [PATCH 01/22] feat: refs #7119 add VehicleState model with data source configuration --- modules/route/back/model-config.json | 3 ++ modules/route/back/models/vehicle-state.json | 29 ++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 modules/route/back/models/vehicle-state.json diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index fb1c5d7fd..8b47c5347 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -35,6 +35,9 @@ "Vehicle": { "dataSource": "vn" }, + "VehicleState": { + "dataSource": "vn" + }, "RoutesMonitor": { "dataSource": "vn" } diff --git a/modules/route/back/models/vehicle-state.json b/modules/route/back/models/vehicle-state.json new file mode 100644 index 000000000..1f71333eb --- /dev/null +++ b/modules/route/back/models/vehicle-state.json @@ -0,0 +1,29 @@ +{ + "name": "VehicleState", + "base": "VnModel", + "options": { + "mysql": { + "table": "vehicleState" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "state": { + "type": "string" + }, + "hasToNotify": { + "type": "number" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file -- 2.40.1 From 39fc19646471d0607bdcfa9170de1b2c34694ef3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 24 Dec 2024 13:01:23 +0100 Subject: [PATCH 02/22] feat: refs #7119 add VehicleEvent and VehicleState models with associated methods and SQL fixtures --- db/dump/fixtures.before.sql | 30 ++++++++--- .../11394-brownAsparagus/00-firstScript.sql | 2 + modules/route/back/methods/vehicle/filter.js | 52 +++++++++++++++++++ modules/route/back/model-config.json | 3 ++ modules/route/back/models/vehicle-event.json | 51 ++++++++++++++++++ modules/route/back/models/vehicle.js | 1 + modules/route/back/models/vehicle.json | 22 ++++++-- 7 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 db/versions/11394-brownAsparagus/00-firstScript.sql create mode 100644 modules/route/back/methods/vehicle/filter.js create mode 100644 modules/route/back/models/vehicle-event.json diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 97ed0ae47..cb9160b6d 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -849,14 +849,14 @@ INSERT INTO `vn`.`deliveryPoint` (`id`, `name`, `ubication`) VALUES (1, 'Gotham','1007 Mountain Drive, Gotham'); -INSERT INTO `vn`.`vehicle`(`id`, `numberPlate`, `tradeMark`, `model`, `companyFk`, `warehouseFk`, `description`, `m3`, `isActive`, `deliveryPointFk`) +INSERT INTO `vn`.`vehicle`(`id`, `numberPlate`, `tradeMark`, `model`, `companyFk`, `warehouseFk`, `description`, `m3`, `isActive`, `deliveryPointFk`, `chassis`, `leasing`) VALUES - (1, '3333-BAT', 'WAYNE INDUSTRIES', 'BATMOBILE', 442, 1, 'The ultimate war machine', 50, 1, 1), - (2, '1111-IMK', 'STARK INDUSTRIES', 'MARK-III', 442, 1, 'Iron-Man Heavy Armor MARK-III', 18, 1, 1), - (3, '2222-IMK', 'STARK INDUSTRIES', 'MARK-VI', 442, 1, 'Iron-Man Heavy Armor MARK-VI', 16, 1, 1), - (4, '3333-IMK', 'STARK INDUSTRIES', 'MARK-VII', 442, 1, 'Iron-Man Heavy Armor MARK-VII', 14, 1, 1), - (5, '4444-IMK', 'STARK INDUSTRIES', 'MARK-XLII', 442, 1, 'Iron-Man Heavy Armor MARK-XLII', 13, 1, 1), - (6, '5555-IMK', 'STARK INDUSTRIES', 'MARK-XLV', 442, 1, 'Iron-Man Heavy Armor MARK-XLV', 12, 0, 1); + (1, '3333-BAT', 'WAYNE INDUSTRIES', 'BATMOBILE', 442, 1, 'The ultimate war machine', 50, 1, 1, 'XCSC133C60', 'Wayne leasing'), + (2, '1111-IMK', 'STARK INDUSTRIES', 'MARK-III', 442, 1, 'Iron-Man Heavy Armor MARK-III', 18, 1, 1, '', ''), + (3, '2222-IMK', 'STARK INDUSTRIES', 'MARK-VI', 442, 1, 'Iron-Man Heavy Armor MARK-VI', 16, 1, 1, '', ''), + (4, '3333-IMK', 'STARK INDUSTRIES', 'MARK-VII', 442, 1, 'Iron-Man Heavy Armor MARK-VII', 14, 1, 1, '', ''), + (5, '4444-IMK', 'STARK INDUSTRIES', 'MARK-XLII', 442, 1, 'Iron-Man Heavy Armor MARK-XLII', 13, 1, 1, '', ''), + (6, '5555-IMK', 'STARK INDUSTRIES', 'MARK-XLV', 442, 1, 'Iron-Man Heavy Armor MARK-XLV', 12, 0, 1, '', ''); INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, `inventoried`) VALUES @@ -4049,3 +4049,19 @@ INSERT IGNORE INTO vn.osrmConfig (id,url,tolerance) INSERT IGNORE INTO vn.inventoryConfig SET id = 1, supplierFk = 4; + +INSERT INTO vn.vehicleState (state, hasToNotify) +VALUES + ('Operativo', NULL), + ('Prestado', NULL), + ('Robado', NULL), + ('Taller', NULL), + ('Targeta SOLRED', NULL), + ('Via T SOLRED', NULL), + ('ITV', NULL); + +INSERT INTO vn.vehicleEvent (started, finished, vehicleStateFk, description, vehicleFk, userFk, notified) +VALUES + ('2000-12-01', '2000-12-02', 4, 'cambio de aceite', 5, 103, NULL), + ('2000-12-15', '2000-12-18', 2, 'viaje fin de curso', 5, 103, NULL), + ('2000-12-20', '2001-01-01', 3, 'llaves puestas', 203, 103, NULL); \ No newline at end of file diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql new file mode 100644 index 000000000..c7137bc7b --- /dev/null +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -0,0 +1,2 @@ +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'); \ No newline at end of file diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js new file mode 100644 index 000000000..9f92ee5ac --- /dev/null +++ b/modules/route/back/methods/vehicle/filter.js @@ -0,0 +1,52 @@ +module.exports = Self => { + Self.remoteMethod('filter', { + description: 'Find all instances of the model matched by filter from the data source.', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/filter`, + verb: `GET` + } + }); + + Self.filter = async id => { + const filter = { + fields: ['id', 'numberPlate', 'tradeMark', 'model', 'm3', 'description', 'isActive', 'warehouseFk', 'companyFk', 'countryCodeFk', 'chassis', 'leasing'], + include: [ + { + relation: 'warehouse', + scope: { + fields: ['id', 'name'] + } + }, + { + relation: 'company', + scope: { + fields: ['id', 'code'] + } + }, + { + relation: 'event', + scope: { + fields: ['vehicleFk', 'vehicleStateFk'], + include: { + relation: 'state', + scope: { + fields: ['id', 'state'] + } + } + } + }, + ] + }; + + return Self.find(filter); + }; +}; diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index 8b47c5347..b951d2560 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -35,6 +35,9 @@ "Vehicle": { "dataSource": "vn" }, + "VehicleEvent": { + "dataSource": "vn" + }, "VehicleState": { "dataSource": "vn" }, diff --git a/modules/route/back/models/vehicle-event.json b/modules/route/back/models/vehicle-event.json new file mode 100644 index 000000000..324076723 --- /dev/null +++ b/modules/route/back/models/vehicle-event.json @@ -0,0 +1,51 @@ +{ + "name": "VehicleEvent", + "base": "VnModel", + "options": { + "mysql": { + "table": "vehicleEvent" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "started": { + "type": "date" + }, + "finished": { + "type": "date" + }, + "vehicleStateFk": { + "type": "number" + }, + "description": { + "type": "string" + }, + "vehicleFk": { + "type": "number" + }, + "userFk": { + "type": "number" + }, + "notified": { + "type": "date" + } + }, + "relations": { + "state": { + "type": "belongsTo", + "model": "VehicleState", + "foreignKey": "vehicleStateFk" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/route/back/models/vehicle.js b/modules/route/back/models/vehicle.js index 73e321443..59aa7cb8b 100644 --- a/modules/route/back/models/vehicle.js +++ b/modules/route/back/models/vehicle.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/vehicle/sorted')(Self); + require('../methods/vehicle/filter')(Self); }; diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index 34a376b89..7dd172017 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "vehicle" + "table": "vehicle" } }, "properties": { @@ -29,6 +29,15 @@ }, "isActive": { "type": "number" + }, + "countryCodeFk": { + "type": "string" + }, + "chassis": { + "type": "string" + }, + "leasing": { + "type": "string" } }, "relations": { @@ -46,14 +55,19 @@ "type": "belongsTo", "model": "DeliveryPoint", "foreignKey": "deliveryPointFk" + }, + "event": { + "type": "belongsTo", + "model": "VehicleEvent", + "foreignKey": "id" } }, "scope": { "where": { "isActive": { - "neq": false - } + "neq": false } + } }, "acls": [ { @@ -63,4 +77,4 @@ "permission": "ALLOW" } ] -} +} \ No newline at end of file -- 2.40.1 From 9aa790ecfd5c0fb67ec0b17d65a59bc8457957bf Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 24 Dec 2024 13:27:32 +0100 Subject: [PATCH 03/22] feat: refs #7119 add isKmTruckRate field to Vehicle model and filter --- modules/route/back/methods/vehicle/filter.js | 2 +- modules/route/back/models/vehicle.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index 9f92ee5ac..608139a4c 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -18,7 +18,7 @@ module.exports = Self => { Self.filter = async id => { const filter = { - fields: ['id', 'numberPlate', 'tradeMark', 'model', 'm3', 'description', 'isActive', 'warehouseFk', 'companyFk', 'countryCodeFk', 'chassis', 'leasing'], + fields: ['id', 'numberPlate', 'tradeMark', 'model', 'm3', 'description', 'isActive', 'warehouseFk', 'companyFk', 'countryCodeFk', 'chassis', 'leasing', 'isKmTruckRate'], include: [ { relation: 'warehouse', diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index 7dd172017..a98c7cab7 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -38,6 +38,9 @@ }, "leasing": { "type": "string" + }, + "isKmTruckRate": { + "type": "number" } }, "relations": { -- 2.40.1 From f8c1e2aacfd2071716d6030ce1224b3bad35b3de Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 26 Dec 2024 16:36:50 +0100 Subject: [PATCH 04/22] feat: refs #7119 add search and filter capabilities to Vehicle model and update related SQL fixtures --- db/dump/fixtures.before.sql | 2 +- modules/route/back/methods/vehicle/filter.js | 88 ++++++++++++++++++-- modules/route/back/models/vehicle.json | 5 +- 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 5516f1329..0189b1137 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4064,4 +4064,4 @@ INSERT INTO vn.vehicleEvent (started, finished, vehicleStateFk, description, veh VALUES ('2000-12-01', '2000-12-02', 4, 'cambio de aceite', 5, 103, NULL), ('2000-12-15', '2000-12-18', 2, 'viaje fin de curso', 5, 103, NULL), - ('2000-12-20', '2001-01-01', 3, 'llaves puestas', 203, 103, NULL); \ No newline at end of file + ('2000-12-20', '2001-01-01', 3, 'llaves puestas', 2, 103, NULL); \ No newline at end of file diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index 608139a4c..b6ba306ac 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -3,8 +3,48 @@ module.exports = Self => { description: 'Find all instances of the model matched by filter from the data source.', accessType: 'READ', accepts: [{ + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, skip and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, { + arg: 'search', + type: 'string', + description: 'Searchs the vehicle by id or numberPlate', + http: {source: 'query'} + }, { arg: 'id', type: 'number' + }, { + arg: 'description', + type: 'string' + }, { + arg: 'companyFk', + type: 'number' + }, { + arg: 'tradeMark', + type: 'string' + }, { + arg: 'numberPlate', + type: 'string' + }, { + arg: 'warehouseFk', + type: 'number' + }, { + arg: 'chassis', + type: 'string' + }, { + arg: 'leasing', + type: 'string' + }, { + arg: 'countryCodeFk', + type: 'string' + }, { + arg: 'isKmTruckRate', + type: 'boolean' + }, { + arg: 'vehicleStateFk', + type: 'number' }], returns: { type: ['object'], @@ -16,8 +56,37 @@ module.exports = Self => { } }); - Self.filter = async id => { - const filter = { + Self.filter = async(filter, search, id, description, companyFk, tradeMark, numberPlate, warehouseFk, chassis, leasing, countryCodeFk, isKmTruckRate, vehicleStateFk, options) => { + const models = Self.app.models; + const myOptions = {}; + const myWhere = {}; + const ids = []; + const {limit, order, skip, where} = filter; + + if (typeof options == 'object') Object.assign(myOptions, options); + + if (search) myWhere.or = [{id: search}, {numberPlate: {like: `%${numberPlate}%`}}]; + if (id) ids.push(id); + if (description) myWhere.description = {like: `%${description}%`}; + if (companyFk) myWhere.companyFk = companyFk; + if (tradeMark) myWhere.tradeMark = {like: `%${tradeMark}%`}; + if (numberPlate) myWhere.numberPlate = {like: `%${numberPlate}%`}; + if (warehouseFk) myWhere.warehouseFk = warehouseFk; + if (chassis) myWhere.chassis = {like: `%${chassis}%`}; + if (leasing) myWhere.leasing = {like: `%${leasing}%`}; + if (countryCodeFk) myWhere.countryCodeFk = countryCodeFk; + if (isKmTruckRate) myWhere.isKmTruckRate = isKmTruckRate; + if (vehicleStateFk) { + ids.push(...await models.VehicleEvent.find({ + fields: ['vehicleFk', 'vehicleStateFk'], + where: {vehicleStateFk}}).map(v => v.vehicleFk)); + } + + const idsLeng = ids.length; + if (idsLeng) myWhere.id = idsLeng == 1 ? ids[0] : {inq: ids}; + Object.assign(where || {}, myWhere); + + const myFilter = { fields: ['id', 'numberPlate', 'tradeMark', 'model', 'm3', 'description', 'isActive', 'warehouseFk', 'companyFk', 'countryCodeFk', 'chassis', 'leasing', 'isKmTruckRate'], include: [ { @@ -41,12 +110,21 @@ module.exports = Self => { scope: { fields: ['id', 'state'] } - } + }, + order: ['started DESC'], + limit: 1 } }, - ] + ], + where: myWhere, + order, + limit, + skip, }; - return Self.find(filter); + return Self.find(myFilter, myOptions).map(v => { + v.__data.event = v.event()[0]; + return v; + }); }; }; diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index a98c7cab7..8419ee684 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -60,9 +60,10 @@ "foreignKey": "deliveryPointFk" }, "event": { - "type": "belongsTo", + "type": "hasMany", "model": "VehicleEvent", - "foreignKey": "id" + "foreignKey": "vehicleFk", + "property": "id" } }, "scope": { -- 2.40.1 From b01e4894c9c3a46e3385be2ebeaeb55589fd2aea Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 26 Dec 2024 17:02:37 +0100 Subject: [PATCH 05/22] feat: refs #7119 remove vehicleStateFk argument from filter method and simplify search logic --- modules/route/back/methods/vehicle/filter.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index b6ba306ac..a6cec0294 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -42,9 +42,6 @@ module.exports = Self => { }, { arg: 'isKmTruckRate', type: 'boolean' - }, { - arg: 'vehicleStateFk', - type: 'number' }], returns: { type: ['object'], @@ -56,17 +53,15 @@ module.exports = Self => { } }); - Self.filter = async(filter, search, id, description, companyFk, tradeMark, numberPlate, warehouseFk, chassis, leasing, countryCodeFk, isKmTruckRate, vehicleStateFk, options) => { - const models = Self.app.models; + Self.filter = async(filter, search, id, description, companyFk, tradeMark, numberPlate, warehouseFk, chassis, leasing, countryCodeFk, isKmTruckRate, options) => { const myOptions = {}; const myWhere = {}; - const ids = []; const {limit, order, skip, where} = filter; if (typeof options == 'object') Object.assign(myOptions, options); - if (search) myWhere.or = [{id: search}, {numberPlate: {like: `%${numberPlate}%`}}]; - if (id) ids.push(id); + if (search) myWhere.or = [{id: search}, {numberPlate: {like: `%${search}%`}}]; + if (id) myWhere.id = id; if (description) myWhere.description = {like: `%${description}%`}; if (companyFk) myWhere.companyFk = companyFk; if (tradeMark) myWhere.tradeMark = {like: `%${tradeMark}%`}; @@ -76,14 +71,7 @@ module.exports = Self => { if (leasing) myWhere.leasing = {like: `%${leasing}%`}; if (countryCodeFk) myWhere.countryCodeFk = countryCodeFk; if (isKmTruckRate) myWhere.isKmTruckRate = isKmTruckRate; - if (vehicleStateFk) { - ids.push(...await models.VehicleEvent.find({ - fields: ['vehicleFk', 'vehicleStateFk'], - where: {vehicleStateFk}}).map(v => v.vehicleFk)); - } - const idsLeng = ids.length; - if (idsLeng) myWhere.id = idsLeng == 1 ? ids[0] : {inq: ids}; Object.assign(where || {}, myWhere); const myFilter = { -- 2.40.1 From 4d7387af18954d4b599bca6d48d0b78421e0e790 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 26 Dec 2024 17:52:36 +0100 Subject: [PATCH 06/22] feat: refs #7119 add deleteById permission for deliveryBoss role in ACL for Vehicle model --- db/versions/11394-brownAsparagus/00-firstScript.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index c7137bc7b..dfc07411e 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -1,2 +1,3 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) - VALUES('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'); \ No newline at end of file + VALUES('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), + ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss'); \ No newline at end of file -- 2.40.1 From 9731d13a9ac401e1f031087f8d7ca1b7045f5340 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 27 Dec 2024 12:21:46 +0100 Subject: [PATCH 07/22] feat: refs #7119 add updateAttributes ACL --- db/versions/11394-brownAsparagus/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index dfc07411e..84d600199 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -1,3 +1,4 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), + ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss'); \ No newline at end of file -- 2.40.1 From 0de4ce9b3c6e005851899930f68f9eb6431fd916 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 27 Dec 2024 15:36:19 +0100 Subject: [PATCH 08/22] feat: refs #7119 add BankPolicy and FuelType models --- db/dump/fixtures.before.sql | 30 ++++++++++++++----- .../11394-brownAsparagus/00-firstScript.sql | 3 +- modules/route/back/model-config.json | 6 ++++ modules/route/back/models/bank-policy.json | 18 +++++++++++ modules/route/back/models/fuel-type.json | 30 +++++++++++++++++++ modules/route/back/models/vehicle.json | 29 ++++++++++++++++++ 6 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 modules/route/back/models/bank-policy.json create mode 100644 modules/route/back/models/fuel-type.json diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 0189b1137..b2d11999d 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -849,14 +849,14 @@ INSERT INTO `vn`.`deliveryPoint` (`id`, `name`, `ubication`) VALUES (1, 'Gotham','1007 Mountain Drive, Gotham'); -INSERT INTO `vn`.`vehicle`(`id`, `numberPlate`, `tradeMark`, `model`, `companyFk`, `warehouseFk`, `description`, `m3`, `isActive`, `deliveryPointFk`, `chassis`, `leasing`) +INSERT INTO `vn`.`vehicle`(`id`, `numberPlate`, `tradeMark`, `model`, `companyFk`, `warehouseFk`, `description`, `m3`, `isActive`, `deliveryPointFk`, `chassis`, `leasing`, `supplierFk`, `fuelTypeFk`, `bankPolicyFk`) VALUES - (1, '3333-BAT', 'WAYNE INDUSTRIES', 'BATMOBILE', 442, 1, 'The ultimate war machine', 50, 1, 1, 'XCSC133C60', 'Wayne leasing'), - (2, '1111-IMK', 'STARK INDUSTRIES', 'MARK-III', 442, 1, 'Iron-Man Heavy Armor MARK-III', 18, 1, 1, '', ''), - (3, '2222-IMK', 'STARK INDUSTRIES', 'MARK-VI', 442, 1, 'Iron-Man Heavy Armor MARK-VI', 16, 1, 1, '', ''), - (4, '3333-IMK', 'STARK INDUSTRIES', 'MARK-VII', 442, 1, 'Iron-Man Heavy Armor MARK-VII', 14, 1, 1, '', ''), - (5, '4444-IMK', 'STARK INDUSTRIES', 'MARK-XLII', 442, 1, 'Iron-Man Heavy Armor MARK-XLII', 13, 1, 1, '', ''), - (6, '5555-IMK', 'STARK INDUSTRIES', 'MARK-XLV', 442, 1, 'Iron-Man Heavy Armor MARK-XLV', 12, 0, 1, '', ''); + (1, '3333-BAT', 'WAYNE INDUSTRIES', 'BATMOBILE', 442, 1, 'The ultimate war machine', 50, 1, 1, 'XCSC133C60', 'Wayne leasing', 1, 1, 1), + (2, '1111-IMK', 'STARK INDUSTRIES', 'MARK-III', 442, 1, 'Iron-Man Heavy Armor MARK-III', 18, 1, 1, '', '', 2, 2, 2), + (3, '2222-IMK', 'STARK INDUSTRIES', 'MARK-VI', 442, 1, 'Iron-Man Heavy Armor MARK-VI', 16, 1, 1, '', '', 442, 2, null), + (4, '3333-IMK', 'STARK INDUSTRIES', 'MARK-VII', 442, 1, 'Iron-Man Heavy Armor MARK-VII', 14, 1, 1, '', '', 442, 3, null), + (5, '4444-IMK', 'STARK INDUSTRIES', 'MARK-XLII', 442, 1, 'Iron-Man Heavy Armor MARK-XLII', 13, 1, 1, '', '', 442, 4, null), + (6, '5555-IMK', 'STARK INDUSTRIES', 'MARK-XLV', 442, 1, 'Iron-Man Heavy Armor MARK-XLV', 12, 0, 1, '', '', 442, 5, null); INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, `inventoried`) VALUES @@ -4064,4 +4064,18 @@ INSERT INTO vn.vehicleEvent (started, finished, vehicleStateFk, description, veh VALUES ('2000-12-01', '2000-12-02', 4, 'cambio de aceite', 5, 103, NULL), ('2000-12-15', '2000-12-18', 2, 'viaje fin de curso', 5, 103, NULL), - ('2000-12-20', '2001-01-01', 3, 'llaves puestas', 2, 103, NULL); \ No newline at end of file + ('2000-12-20', '2001-01-01', 3, 'llaves puestas', 2, 103, NULL); + +INSERT INTO vn.fuelType (id, name, code) +VALUES + (1, 'gasoil', 'gasoil'), + (2, 'gas', 'gas'), + (3, 'adblue', 'adblue'), + (4, 'gasolina', 'gasolina'), + (5, 'gasoil-frigo', 'gasoil-frigo'), + (6, 'electrico', 'electric'); + +INSERT INTO vn.bankPolicy (id, `ref`, amount, committedFee, nonCommittedFee, annualFee, started, ended, accountingFk, companyFk, supplierFk, description, hasGuarantee, dmsFk, notaryFk, currencyFk, amortizationTypeFk, periodicityTypeFk, insuranceExpired) +VALUES + (1, '11112222', 500000.0, 0.028, 0.0, 0.001, '2001-01-01', '2001-02-01', 1, 442, NULL, NULL, 0, NULL, NULL, 1, NULL, NULL, NULL), + (2, '33334444', 100000.0, 0.017, 0.0, 0.0, '2001-01-01', '2001-02-01', 1, 2, NULL, NULL, 0, NULL, NULL, 2, NULL, NULL, NULL); \ No newline at end of file diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index 84d600199..d02482efd 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -1,4 +1,5 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) - VALUES('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), + VALUES ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), + ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss'); \ No newline at end of file diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index b951d2560..42b71f5f1 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -5,12 +5,18 @@ "AgencyTermConfig": { "dataSource": "vn" }, + "BankPolicy": { + "dataSource": "vn" + }, "Cmr": { "dataSource": "vn" }, "DeliveryPoint": { "dataSource": "vn" }, + "FuelType": { + "dataSource": "vn" + }, "RoadmapAddress": { "dataSource": "vn" }, diff --git a/modules/route/back/models/bank-policy.json b/modules/route/back/models/bank-policy.json new file mode 100644 index 000000000..edbc636ff --- /dev/null +++ b/modules/route/back/models/bank-policy.json @@ -0,0 +1,18 @@ +{ + "name": "BankPolicy", + "base": "VnModel", + "options": { + "mysql": { + "table": "bankPolicy" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "ref": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/modules/route/back/models/fuel-type.json b/modules/route/back/models/fuel-type.json new file mode 100644 index 000000000..c7f96b325 --- /dev/null +++ b/modules/route/back/models/fuel-type.json @@ -0,0 +1,30 @@ +{ + "name": "FuelType", + "base": "VnModel", + "options": { + "mysql": { + "table": "fuelType" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string" + }, + "code": { + "type": "string" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "employee", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index 8419ee684..c5b6eab5b 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -41,6 +41,15 @@ }, "isKmTruckRate": { "type": "number" + }, + "fuelTypeFk": { + "type": "number" + }, + "import": { + "type": "number" + }, + "vin": { + "type": "string" } }, "relations": { @@ -64,6 +73,26 @@ "model": "VehicleEvent", "foreignKey": "vehicleFk", "property": "id" + }, + "supplier": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "supplierFk" + }, + "supplierCooler": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "supplierCoolerFk" + }, + "bankPolicy": { + "type": "belongsTo", + "model": "BankPolicy", + "foreignKey": "bankPolicyFk" + }, + "fuelType": { + "type": "belongsTo", + "model": "FuelType", + "foreignKey": "fuelTypeFk" } }, "scope": { -- 2.40.1 From 921edb238cdb1eb700e46429f6ec3db3846c0d85 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 27 Dec 2024 16:55:59 +0100 Subject: [PATCH 09/22] feat: refs #7119 add Ppe model and establish relationships in Vehicle model --- db/dump/fixtures.before.sql | 49 ++++++++++++++------------ modules/route/back/model-config.json | 3 ++ modules/route/back/models/ppe.json | 23 ++++++++++++ modules/route/back/models/vehicle.json | 6 ++++ 4 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 modules/route/back/models/ppe.json diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index b2d11999d..d5562d000 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4051,31 +4051,36 @@ INSERT IGNORE INTO vn.inventoryConfig supplierFk = 4; INSERT INTO vn.vehicleState (state, hasToNotify) -VALUES - ('Operativo', NULL), - ('Prestado', NULL), - ('Robado', NULL), - ('Taller', NULL), - ('Targeta SOLRED', NULL), - ('Via T SOLRED', NULL), - ('ITV', NULL); + VALUES + ('Operativo', NULL), + ('Prestado', NULL), + ('Robado', NULL), + ('Taller', NULL), + ('Targeta SOLRED', NULL), + ('Via T SOLRED', NULL), + ('ITV', NULL); INSERT INTO vn.vehicleEvent (started, finished, vehicleStateFk, description, vehicleFk, userFk, notified) -VALUES - ('2000-12-01', '2000-12-02', 4, 'cambio de aceite', 5, 103, NULL), - ('2000-12-15', '2000-12-18', 2, 'viaje fin de curso', 5, 103, NULL), - ('2000-12-20', '2001-01-01', 3, 'llaves puestas', 2, 103, NULL); + VALUES + ('2000-12-01', '2000-12-02', 4, 'cambio de aceite', 5, 103, NULL), + ('2000-12-15', '2000-12-18', 2, 'viaje fin de curso', 5, 103, NULL), + ('2000-12-20', '2001-01-01', 3, 'llaves puestas', 2, 103, NULL); INSERT INTO vn.fuelType (id, name, code) -VALUES - (1, 'gasoil', 'gasoil'), - (2, 'gas', 'gas'), - (3, 'adblue', 'adblue'), - (4, 'gasolina', 'gasolina'), - (5, 'gasoil-frigo', 'gasoil-frigo'), - (6, 'electrico', 'electric'); + VALUES + (1, 'gasoil', 'gasoil'), + (2, 'gas', 'gas'), + (3, 'adblue', 'adblue'), + (4, 'gasolina', 'gasolina'), + (5, 'gasoil-frigo', 'gasoil-frigo'), + (6, 'electrico', 'electric'); INSERT INTO vn.bankPolicy (id, `ref`, amount, committedFee, nonCommittedFee, annualFee, started, ended, accountingFk, companyFk, supplierFk, description, hasGuarantee, dmsFk, notaryFk, currencyFk, amortizationTypeFk, periodicityTypeFk, insuranceExpired) -VALUES - (1, '11112222', 500000.0, 0.028, 0.0, 0.001, '2001-01-01', '2001-02-01', 1, 442, NULL, NULL, 0, NULL, NULL, 1, NULL, NULL, NULL), - (2, '33334444', 100000.0, 0.017, 0.0, 0.0, '2001-01-01', '2001-02-01', 1, 2, NULL, NULL, 0, NULL, NULL, 2, NULL, NULL, NULL); \ No newline at end of file + VALUES + (1, '11112222', 500000.0, 0.028, 0.0, 0.001, '2001-01-01', '2001-02-01', 1, 442, NULL, NULL, 0, NULL, NULL, 1, NULL, NULL, NULL), + (2, '33334444', 100000.0, 0.017, 0.0, 0.0, '2001-01-01', '2001-02-01', 1, 2, NULL, NULL, 0, NULL, NULL, 2, NULL, NULL, NULL); + +INSERT INTO vn.ppe (id, amortization, firstAmortizated, lastAmortizated, finished, value, planFk, groupFk, account, endowment, elementAccount, nature, location, discharged, cause, isInvestmentAsset, workerFk, companyFk, description, isDone) + VALUES + (1, 0.00, '2001-01-01', NULL, NULL, 700.95, 16, 4, '3456000000', '4320000000', '12345', 'INMOVILIZADO', 'V02', NULL, NULL, 0, NULL, 442, 'UTILLAJE LASER ROTATIVO AUTONIVELANTE 500M', NULL), + (2, 0.00, '2001-01-01', NULL, NULL, 400.00, 16, 4, '5678000000', '1230000000', '67891', 'INMOVILIZADO', 'V02', NULL, NULL, 0, NULL, 442, 'UTILLAJE BALANZA Z100 150KILOS', NULL); \ No newline at end of file diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index 42b71f5f1..c8c67a361 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -17,6 +17,9 @@ "FuelType": { "dataSource": "vn" }, + "Ppe": { + "dataSource": "vn" + }, "RoadmapAddress": { "dataSource": "vn" }, diff --git a/modules/route/back/models/ppe.json b/modules/route/back/models/ppe.json new file mode 100644 index 000000000..7af5cb684 --- /dev/null +++ b/modules/route/back/models/ppe.json @@ -0,0 +1,23 @@ +{ + "name": "Ppe", + "base": "VnModel", + "options": { + "mysql": { + "table": "ppe" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "delivery", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index c5b6eab5b..dbf78f7d1 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -93,6 +93,12 @@ "type": "belongsTo", "model": "FuelType", "foreignKey": "fuelTypeFk" + }, + "ppe": { + "type": "hasOne", + "model": "Ppe", + "foreignKey": "id", + "property": "ppeFk" } }, "scope": { -- 2.40.1 From 68e42206c8f2054084112505871e2596f5a1f345 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 30 Dec 2024 17:31:56 +0100 Subject: [PATCH 10/22] feat: refs #7119 enhance vehicle filter method with additional parameters and improve SQL query structure --- modules/route/back/methods/vehicle/filter.js | 133 +++++++++++-------- modules/route/back/models/vehicle.json | 3 + 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index a6cec0294..bc2186e3a 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -1,5 +1,8 @@ +const {ParameterizedSQL} = require('loopback-connector'); +const {buildFilter, mergeFilters} = require('vn-loopback/util/filter'); + module.exports = Self => { - Self.remoteMethod('filter', { + Self.remoteMethodCtx('filter', { description: 'Find all instances of the model matched by filter from the data source.', accessType: 'READ', accepts: [{ @@ -42,6 +45,9 @@ module.exports = Self => { }, { arg: 'isKmTruckRate', type: 'boolean' + }, { + arg: 'vehicleStateFk', + type: 'number' }], returns: { type: ['object'], @@ -53,66 +59,79 @@ module.exports = Self => { } }); - Self.filter = async(filter, search, id, description, companyFk, tradeMark, numberPlate, warehouseFk, chassis, leasing, countryCodeFk, isKmTruckRate, options) => { + Self.filter = async(ctx, filter, options) => { + const conn = Self.dataSource.connector; const myOptions = {}; - const myWhere = {}; - const {limit, order, skip, where} = filter; if (typeof options == 'object') Object.assign(myOptions, options); - if (search) myWhere.or = [{id: search}, {numberPlate: {like: `%${search}%`}}]; - if (id) myWhere.id = id; - if (description) myWhere.description = {like: `%${description}%`}; - if (companyFk) myWhere.companyFk = companyFk; - if (tradeMark) myWhere.tradeMark = {like: `%${tradeMark}%`}; - if (numberPlate) myWhere.numberPlate = {like: `%${numberPlate}%`}; - if (warehouseFk) myWhere.warehouseFk = warehouseFk; - if (chassis) myWhere.chassis = {like: `%${chassis}%`}; - if (leasing) myWhere.leasing = {like: `%${leasing}%`}; - if (countryCodeFk) myWhere.countryCodeFk = countryCodeFk; - if (isKmTruckRate) myWhere.isKmTruckRate = isKmTruckRate; - - Object.assign(where || {}, myWhere); - - const myFilter = { - fields: ['id', 'numberPlate', 'tradeMark', 'model', 'm3', 'description', 'isActive', 'warehouseFk', 'companyFk', 'countryCodeFk', 'chassis', 'leasing', 'isKmTruckRate'], - include: [ - { - relation: 'warehouse', - scope: { - fields: ['id', 'name'] - } - }, - { - relation: 'company', - scope: { - fields: ['id', 'code'] - } - }, - { - relation: 'event', - scope: { - fields: ['vehicleFk', 'vehicleStateFk'], - include: { - relation: 'state', - scope: { - fields: ['id', 'state'] - } - }, - order: ['started DESC'], - limit: 1 - } - }, - ], - where: myWhere, - order, - limit, - skip, - }; - - return Self.find(myFilter, myOptions).map(v => { - v.__data.event = v.event()[0]; - return v; + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'search': + return {or: [{'v.id': value}, {numberPlate: {like: `%${value}%`}}]}; + case 'id': + return {id: value}; + case 'description': + return {description: {like: `%${value}%`}}; + case 'companyFk': + return {companyFk: value}; + case 'tradeMark': + return {tradeMark: {like: `%${value}%`}}; + case 'numberPlate': + return {numberPlate: {like: `%${value}%`}}; + case 'warehouseFk': + return {warehouseFk: value}; + case 'chassis': + return {chassis: {like: `%${value}%`}}; + case 'leasing': + return {leasing: {like: `%${value}%`}}; + case 'countryCodeFk': + return {countryCodeFk: value}; + case 'isKmTruckRate': + return {isKmTruckRate: value}; + case 'vehicleStateFk': + return {vehicleStateFk: value}; + } }); + + const myFilter = mergeFilters(filter, {where}); + + const stmt = new ParameterizedSQL(` + SELECT v.id, + v.numberPlate, + v.tradeMark, + v.model, + v.m3, + v.description, + v.isActive, + v.countryCodeFk, + v.chassis, + v.leasing, + v.isKmTruckRate, + w.name as warehouse, + c.code as company, + sub.state + FROM vehicle v + LEFT JOIN warehouse w ON w.id = v.warehouseFk + LEFT JOIN company c ON c.id = v.companyFk + LEFT JOIN ( + SELECT e.vehicleFk, + e.vehicleStateFk, + s.state, + ROW_NUMBER() OVER (PARTITION BY e.vehicleFk ORDER BY e.started DESC) as rn + FROM vehicleEvent e + LEFT JOIN vehicleState s ON e.vehicleStateFk = s.id + ) sub ON sub.vehicleFk = v.id AND sub.rn = 1 + ` + ); + + const sqlWhere = conn.makeWhere(myFilter.where); + stmt.merge(sqlWhere); + stmt.merge(conn.makePagination(myFilter)); + + const sql = ParameterizedSQL.join([stmt], ';'); + const result = await conn.executeStmt(sql, myOptions); + + return result; }; }; diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index dbf78f7d1..9269cdebb 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -50,6 +50,9 @@ }, "vin": { "type": "string" + }, + "ppeFk": { + "type": "number" } }, "relations": { -- 2.40.1 From bc495ed51e947e45072610e37ca2a6f18aedcca4 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 30 Dec 2024 17:55:27 +0100 Subject: [PATCH 11/22] feat: refs #7119 add VehicleNotes model and update vehicle filter SQL query --- modules/route/back/methods/vehicle/filter.js | 2 +- modules/route/back/model-config.json | 3 ++ modules/route/back/models/vehicle-notes.json | 35 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 modules/route/back/models/vehicle-notes.json diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index bc2186e3a..17c132c2c 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -118,7 +118,7 @@ module.exports = Self => { SELECT e.vehicleFk, e.vehicleStateFk, s.state, - ROW_NUMBER() OVER (PARTITION BY e.vehicleFk ORDER BY e.started DESC) as rn + ROW_NUMBER() OVER (PARTITION BY e.vehicleFk ORDER BY e.started DESC) rn FROM vehicleEvent e LEFT JOIN vehicleState s ON e.vehicleStateFk = s.id ) sub ON sub.vehicleFk = v.id AND sub.rn = 1 diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index c8c67a361..07054061f 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -47,6 +47,9 @@ "VehicleEvent": { "dataSource": "vn" }, + "VehicleNotes": { + "dataSource": "vn" + }, "VehicleState": { "dataSource": "vn" }, diff --git a/modules/route/back/models/vehicle-notes.json b/modules/route/back/models/vehicle-notes.json new file mode 100644 index 000000000..922f9b14b --- /dev/null +++ b/modules/route/back/models/vehicle-notes.json @@ -0,0 +1,35 @@ +{ + "name": "VehicleNotes", + "base": "VnModel", + "options": { + "mysql": { + "table": "vehicleNotes" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "vehicleFk": { + "type": "number" + }, + "created": { + "type": "date" + }, + "note": { + "type": "string" + }, + "userFk": { + "type": "number" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "delivery", + "permission": "ALLOW" + } + ] +} \ No newline at end of file -- 2.40.1 From 946d08e5432a34e0259ac0fa01e90c5da76780c7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 20 Jan 2025 17:29:18 +0100 Subject: [PATCH 12/22] feat: refs #7119 update ACLs and remove unused models for vehicle management --- .../11394-brownAsparagus/00-firstScript.sql | 2 + modules/route/back/methods/vehicle/filter.js | 10 ++-- modules/route/back/model-config.json | 6 --- modules/route/back/models/fuel-type.json | 2 +- modules/route/back/models/ppe.json | 10 +--- modules/route/back/models/vehicle-event.json | 51 ------------------- modules/route/back/models/vehicle-notes.json | 35 ------------- modules/route/back/models/vehicle-state.json | 10 +--- 8 files changed, 9 insertions(+), 117 deletions(-) delete mode 100644 modules/route/back/models/vehicle-event.json delete mode 100644 modules/route/back/models/vehicle-notes.json diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index d02482efd..4d6cedb69 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -2,4 +2,6 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p VALUES ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), + ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery' ), + ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery' ), ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss'); \ No newline at end of file diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index 17c132c2c..ea2a94281 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -92,9 +92,9 @@ module.exports = Self => { case 'vehicleStateFk': return {vehicleStateFk: value}; } - }); + }) || {}; - const myFilter = mergeFilters(filter, {where}); + const myFilter = mergeFilters(filter, {where: {...where, isActive: true}}); const stmt = new ParameterizedSQL(` SELECT v.id, @@ -122,16 +122,14 @@ module.exports = Self => { FROM vehicleEvent e LEFT JOIN vehicleState s ON e.vehicleStateFk = s.id ) sub ON sub.vehicleFk = v.id AND sub.rn = 1 - ` - ); + `); const sqlWhere = conn.makeWhere(myFilter.where); stmt.merge(sqlWhere); stmt.merge(conn.makePagination(myFilter)); const sql = ParameterizedSQL.join([stmt], ';'); - const result = await conn.executeStmt(sql, myOptions); - return result; + return conn.executeStmt(sql, myOptions); }; }; diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index 07054061f..16e6d6967 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -44,12 +44,6 @@ "Vehicle": { "dataSource": "vn" }, - "VehicleEvent": { - "dataSource": "vn" - }, - "VehicleNotes": { - "dataSource": "vn" - }, "VehicleState": { "dataSource": "vn" }, diff --git a/modules/route/back/models/fuel-type.json b/modules/route/back/models/fuel-type.json index c7f96b325..d42614837 100644 --- a/modules/route/back/models/fuel-type.json +++ b/modules/route/back/models/fuel-type.json @@ -23,7 +23,7 @@ { "accessType": "READ", "principalType": "ROLE", - "principalId": "employee", + "principalId": "$everyone", "permission": "ALLOW" } ] diff --git a/modules/route/back/models/ppe.json b/modules/route/back/models/ppe.json index 7af5cb684..0825d348c 100644 --- a/modules/route/back/models/ppe.json +++ b/modules/route/back/models/ppe.json @@ -11,13 +11,5 @@ "type": "number", "id": true } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "delivery", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file diff --git a/modules/route/back/models/vehicle-event.json b/modules/route/back/models/vehicle-event.json deleted file mode 100644 index 324076723..000000000 --- a/modules/route/back/models/vehicle-event.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "VehicleEvent", - "base": "VnModel", - "options": { - "mysql": { - "table": "vehicleEvent" - } - }, - "properties": { - "id": { - "type": "number", - "id": true - }, - "started": { - "type": "date" - }, - "finished": { - "type": "date" - }, - "vehicleStateFk": { - "type": "number" - }, - "description": { - "type": "string" - }, - "vehicleFk": { - "type": "number" - }, - "userFk": { - "type": "number" - }, - "notified": { - "type": "date" - } - }, - "relations": { - "state": { - "type": "belongsTo", - "model": "VehicleState", - "foreignKey": "vehicleStateFk" - } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] -} \ No newline at end of file diff --git a/modules/route/back/models/vehicle-notes.json b/modules/route/back/models/vehicle-notes.json deleted file mode 100644 index 922f9b14b..000000000 --- a/modules/route/back/models/vehicle-notes.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "VehicleNotes", - "base": "VnModel", - "options": { - "mysql": { - "table": "vehicleNotes" - } - }, - "properties": { - "id": { - "type": "number", - "id": true - }, - "vehicleFk": { - "type": "number" - }, - "created": { - "type": "date" - }, - "note": { - "type": "string" - }, - "userFk": { - "type": "number" - } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "delivery", - "permission": "ALLOW" - } - ] -} \ No newline at end of file diff --git a/modules/route/back/models/vehicle-state.json b/modules/route/back/models/vehicle-state.json index 1f71333eb..b53719f63 100644 --- a/modules/route/back/models/vehicle-state.json +++ b/modules/route/back/models/vehicle-state.json @@ -17,13 +17,5 @@ "hasToNotify": { "type": "number" } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file -- 2.40.1 From 3d2a7cfb6695e3243a7a926ac164f9f2392d104a Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 20 Jan 2025 18:05:33 +0100 Subject: [PATCH 13/22] feat: refs #7119 update ACLs for vehicle management and refine vehicle filter logic --- .../11394-brownAsparagus/00-firstScript.sql | 15 +++++++----- modules/route/back/methods/vehicle/filter.js | 2 +- modules/route/back/models/vehicle.json | 24 +++++++++---------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index 4d6cedb69..72fb6b13d 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -1,7 +1,10 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) - VALUES ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), - ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), - ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), - ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery' ), - ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery' ), - ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss'); \ No newline at end of file + VALUES ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'findById', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative' ), + ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative' ), + ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', '__get__active', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index ea2a94281..11cc4d82a 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -94,7 +94,7 @@ module.exports = Self => { } }) || {}; - const myFilter = mergeFilters(filter, {where: {...where, isActive: true}}); + const myFilter = mergeFilters(filter, {where}); const stmt = new ParameterizedSQL(` SELECT v.id, diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index 9269cdebb..e6d58de99 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -104,19 +104,17 @@ "property": "ppeFk" } }, - "scope": { - "where": { - "isActive": { - "neq": false + "scopes": { + "active": { + "fields": [ + "id", + "numberPlate" + ], + "where": { + "isActive": { + "neq": false + } } } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file -- 2.40.1 From 55a0a5bc9a317f46b22ec3d5ae19eecc8f4f8d5c Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 21 Jan 2025 11:52:09 +0100 Subject: [PATCH 14/22] feat: refs #7119 add delivery role permissions --- db/versions/11394-brownAsparagus/00-firstScript.sql | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index 72fb6b13d..77dfab7d3 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -1,10 +1,17 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), ('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), ('Vehicle', 'findById', 'READ', 'ALLOW', 'ROLE', 'administrative'), ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative' ), + ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), + ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative' ), + ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery' ), ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), ('Vehicle', '__get__active', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file -- 2.40.1 From 2ae0097fa821b1335f382d63fe503fa5d28f139a Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 21 Jan 2025 15:48:20 +0100 Subject: [PATCH 15/22] feat: refs #7119 add vehicle type management and delivery role permissions --- db/dump/fixtures.before.sql | 11 +++++++++- .../11394-brownAsparagus/00-firstScript.sql | 21 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 289944636..17f7cdf2f 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4090,4 +4090,13 @@ INSERT INTO vn.bankPolicy (id, `ref`, amount, committedFee, nonCommittedFee, ann INSERT INTO vn.ppe (id, amortization, firstAmortizated, lastAmortizated, finished, value, planFk, groupFk, account, endowment, elementAccount, nature, location, discharged, cause, isInvestmentAsset, workerFk, companyFk, description, isDone) VALUES (1, 0.00, '2001-01-01', NULL, NULL, 700.95, 16, 4, '3456000000', '4320000000', '12345', 'INMOVILIZADO', 'V02', NULL, NULL, 0, NULL, 442, 'UTILLAJE LASER ROTATIVO AUTONIVELANTE 500M', NULL), - (2, 0.00, '2001-01-01', NULL, NULL, 400.00, 16, 4, '5678000000', '1230000000', '67891', 'INMOVILIZADO', 'V02', NULL, NULL, 0, NULL, 442, 'UTILLAJE BALANZA Z100 150KILOS', NULL); \ No newline at end of file + (2, 0.00, '2001-01-01', NULL, NULL, 400.00, 16, 4, '5678000000', '1230000000', '67891', 'INMOVILIZADO', 'V02', NULL, NULL, 0, NULL, 442, 'UTILLAJE BALANZA Z100 150KILOS', NULL); + +INSERT IGNORE INTO vn.vehicleType (id, name) + VALUES (1,'vehículo empresa'), + (2, 'furgoneta'), + (3, 'cabeza tractora'), + (4, 'remolque'); + + + \ No newline at end of file diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index 77dfab7d3..51034c86b 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -1,3 +1,4 @@ +USE vn; INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'administrative'), ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), @@ -14,4 +15,22 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery' ), ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), - ('Vehicle', '__get__active', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file + ('Vehicle', '__get__active', 'READ', 'ALLOW', 'ROLE', 'employee'); + +ALTER TABLE vehicle ADD COLUMN importCooler decimal(10,2) DEFAULT NULL; + + +CREATE TABLE IF NOT EXISTS vehicleType ( + id INT(11) PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(45) NOT NULL +); + +INSERT IGNORE INTO vehicleType (id, name) + VALUES (1,'vehículo empresa'), + (2, 'furgoneta'), + (3, 'cabeza tractora'), + (4, 'remolque'); +ALTER TABLE vehicle ADD COLUMN vehicleTypeFk INT(11) DEFAULT 1; + +ALTER TABLE vehicle ADD CONSTRAINT fk_vehicle_vehicleType FOREIGN KEY (vehicleTypeFk) REFERENCES vehicleType(id); + -- 2.40.1 From 3ea67675dad4bb7b9def51ce4acb56367524a352 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 23 Jan 2025 10:53:53 +0100 Subject: [PATCH 16/22] feat: refs #7119 add VehicleType model and update vehicle permissions for delivery roles --- .../11394-brownAsparagus/00-firstScript.sql | 22 ++++++------- modules/route/back/methods/vehicle/filter.js | 32 +++++++------------ modules/route/back/model-config.json | 3 ++ modules/route/back/models/vehicle-type.json | 19 +++++++++++ modules/route/back/models/vehicle.json | 9 ++++++ 5 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 modules/route/back/models/vehicle-type.json diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index 51034c86b..686262727 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -1,25 +1,24 @@ USE vn; + INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery'), + ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), + ('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('Vehicle', 'findById', 'READ', 'ALLOW', 'ROLE', 'administrative'), ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), - ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), + ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), + ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery'), + ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative' ), - ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'delivery' ), + ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant' ), ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), - ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), + ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'), + ('VehicleType', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Vehicle', '__get__active', 'READ', 'ALLOW', 'ROLE', 'employee'); -ALTER TABLE vehicle ADD COLUMN importCooler decimal(10,2) DEFAULT NULL; - - CREATE TABLE IF NOT EXISTS vehicleType ( id INT(11) PRIMARY KEY AUTO_INCREMENT, name VARCHAR(45) NOT NULL @@ -30,7 +29,8 @@ INSERT IGNORE INTO vehicleType (id, name) (2, 'furgoneta'), (3, 'cabeza tractora'), (4, 'remolque'); -ALTER TABLE vehicle ADD COLUMN vehicleTypeFk INT(11) DEFAULT 1; +ALTER TABLE vehicle ADD COLUMN importCooler decimal(10,2) DEFAULT NULL; +ALTER TABLE vehicle ADD COLUMN vehicleTypeFk INT(11) DEFAULT 1; ALTER TABLE vehicle ADD CONSTRAINT fk_vehicle_vehicleType FOREIGN KEY (vehicleTypeFk) REFERENCES vehicleType(id); diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index 11cc4d82a..7e8fb3641 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -43,8 +43,8 @@ module.exports = Self => { arg: 'countryCodeFk', type: 'string' }, { - arg: 'isKmTruckRate', - type: 'boolean' + arg: 'vehicleTypeFk', + type: 'number' }, { arg: 'vehicleStateFk', type: 'number' @@ -69,28 +69,19 @@ module.exports = Self => { switch (param) { case 'search': return {or: [{'v.id': value}, {numberPlate: {like: `%${value}%`}}]}; - case 'id': - return {id: value}; case 'description': - return {description: {like: `%${value}%`}}; - case 'companyFk': - return {companyFk: value}; case 'tradeMark': - return {tradeMark: {like: `%${value}%`}}; case 'numberPlate': - return {numberPlate: {like: `%${value}%`}}; - case 'warehouseFk': - return {warehouseFk: value}; case 'chassis': - return {chassis: {like: `%${value}%`}}; case 'leasing': - return {leasing: {like: `%${value}%`}}; + return {[param]: {like: `%${value}%`}}; + case 'id': + case 'companyFk': + case 'warehouseFk': case 'countryCodeFk': - return {countryCodeFk: value}; - case 'isKmTruckRate': - return {isKmTruckRate: value}; case 'vehicleStateFk': - return {vehicleStateFk: value}; + case 'vehicleTypeFk': + return {[param]: value}; } }) || {}; @@ -107,11 +98,12 @@ module.exports = Self => { v.countryCodeFk, v.chassis, v.leasing, - v.isKmTruckRate, - w.name as warehouse, - c.code as company, + vt.name type, + w.name warehouse, + c.code company, sub.state FROM vehicle v + JOIN vehicleType vt ON vt.id = v.vehicleTypeFk LEFT JOIN warehouse w ON w.id = v.warehouseFk LEFT JOIN company c ON c.id = v.companyFk LEFT JOIN ( diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index 16e6d6967..3a7c9e06b 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -47,6 +47,9 @@ "VehicleState": { "dataSource": "vn" }, + "VehicleType": { + "dataSource": "vn" + }, "RoutesMonitor": { "dataSource": "vn" } diff --git a/modules/route/back/models/vehicle-type.json b/modules/route/back/models/vehicle-type.json new file mode 100644 index 000000000..34beb6dfb --- /dev/null +++ b/modules/route/back/models/vehicle-type.json @@ -0,0 +1,19 @@ +{ + "name": "VehicleType", + "base": "VnModel", + "options": { + "mysql": { + "table": "vehicleType" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index e6d58de99..95eac7251 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -53,6 +53,9 @@ }, "ppeFk": { "type": "number" + }, + "vehicleTypeFk": { + "type": "number" } }, "relations": { @@ -102,6 +105,12 @@ "model": "Ppe", "foreignKey": "id", "property": "ppeFk" + }, + "type": { + "type": "hasOne", + "model": "VehicleType", + "foreignKey": "id", + "property": "vehicleTypeFk" } }, "scopes": { -- 2.40.1 From 3a449896cdbe15900c8021100d301405cb1481b7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 23 Jan 2025 18:02:53 +0100 Subject: [PATCH 17/22] feat: refs #7119 update vehicle permissions and enhance vehicle model with new fields --- db/versions/11394-brownAsparagus/00-firstScript.sql | 13 +++++++++---- modules/route/back/models/vehicle.json | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/db/versions/11394-brownAsparagus/00-firstScript.sql b/db/versions/11394-brownAsparagus/00-firstScript.sql index 686262727..13b6cfa0d 100644 --- a/db/versions/11394-brownAsparagus/00-firstScript.sql +++ b/db/versions/11394-brownAsparagus/00-firstScript.sql @@ -6,19 +6,24 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p ('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), ('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('Vehicle', 'findById', 'READ', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), + ('Vehicle', '__get__active', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), ('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'), + ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'), + ('Vehicle', 'create', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('Vehicle', 'create', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), ('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'), ('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative' ), ('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant' ), - ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), - ('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'), ('VehicleType', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Vehicle', '__get__active', 'READ', 'ALLOW', 'ROLE', 'employee'); - + ('DeliveryPoint', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'), + ('DeliveryPoint', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'); + CREATE TABLE IF NOT EXISTS vehicleType ( id INT(11) PRIMARY KEY AUTO_INCREMENT, name VARCHAR(45) NOT NULL diff --git a/modules/route/back/models/vehicle.json b/modules/route/back/models/vehicle.json index 95eac7251..d64f3df79 100644 --- a/modules/route/back/models/vehicle.json +++ b/modules/route/back/models/vehicle.json @@ -48,6 +48,9 @@ "import": { "type": "number" }, + "importCooler": { + "type": "number" + }, "vin": { "type": "string" }, @@ -56,6 +59,9 @@ }, "vehicleTypeFk": { "type": "number" + }, + "deliveryPointFk": { + "type": "number" } }, "relations": { -- 2.40.1 From 3fba81b41e8bc7ae1162dabcd41944fa525e76d3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 24 Jan 2025 10:46:35 +0100 Subject: [PATCH 18/22] feat: refs #7119 add 'id' filter option and enhance bank policy model with dmsFk field --- modules/route/back/methods/vehicle/filter.js | 11 ++++++----- modules/route/back/models/bank-policy.json | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index 7e8fb3641..cb55f5f3c 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -69,13 +69,14 @@ module.exports = Self => { switch (param) { case 'search': return {or: [{'v.id': value}, {numberPlate: {like: `%${value}%`}}]}; + case 'id': + return {'v.id': value}; case 'description': case 'tradeMark': case 'numberPlate': case 'chassis': case 'leasing': return {[param]: {like: `%${value}%`}}; - case 'id': case 'companyFk': case 'warehouseFk': case 'countryCodeFk': @@ -83,9 +84,9 @@ module.exports = Self => { case 'vehicleTypeFk': return {[param]: value}; } - }) || {}; + }); - const myFilter = mergeFilters(filter, {where}); + filter = mergeFilters(filter, {where}); const stmt = new ParameterizedSQL(` SELECT v.id, @@ -116,9 +117,9 @@ module.exports = Self => { ) sub ON sub.vehicleFk = v.id AND sub.rn = 1 `); - const sqlWhere = conn.makeWhere(myFilter.where); + const sqlWhere = conn.makeWhere(filter.where); stmt.merge(sqlWhere); - stmt.merge(conn.makePagination(myFilter)); + stmt.merge(conn.makePagination(filter)); const sql = ParameterizedSQL.join([stmt], ';'); diff --git a/modules/route/back/models/bank-policy.json b/modules/route/back/models/bank-policy.json index edbc636ff..55a409a67 100644 --- a/modules/route/back/models/bank-policy.json +++ b/modules/route/back/models/bank-policy.json @@ -13,6 +13,9 @@ }, "ref": { "type": "string" + }, + "dmsFk": { + "type": "number" } } } \ No newline at end of file -- 2.40.1 From ec7bbd13b131330caad46ebfaa2b81bd5aaa4b2e Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 24 Jan 2025 16:37:35 +0100 Subject: [PATCH 19/22] refactor: refs #7119 update vehicle filter logic and improve test cases --- modules/route/back/methods/vehicle/filter.js | 2 - .../back/methods/vehicle/specs/filter.spec.js | 93 ++++++++++--------- 2 files changed, 49 insertions(+), 46 deletions(-) diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index ef87c1448..fa0b84758 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -71,8 +71,6 @@ module.exports = Self => { return /^\d+$/.test(value) ? {'v.id': value} : {numberPlate: {like: `%${value}%`}}; - case 'id': - return {'v.id': value}; case 'description': case 'tradeMark': case 'numberPlate': diff --git a/modules/route/back/methods/vehicle/specs/filter.spec.js b/modules/route/back/methods/vehicle/specs/filter.spec.js index ab718f06e..52e0b8a39 100644 --- a/modules/route/back/methods/vehicle/specs/filter.spec.js +++ b/modules/route/back/methods/vehicle/specs/filter.spec.js @@ -1,6 +1,6 @@ const {models} = require('vn-loopback/server/server'); -fdescribe('Vehicle filter()', () => { +describe('Vehicle filter()', () => { const deliveryAssiId = 123; const ctx = beforeAll.getCtx(deliveryAssiId); let options; @@ -30,7 +30,7 @@ fdescribe('Vehicle filter()', () => { expect(searchResult2.numberPlate).toEqual(numberPlate); }); - it('should return the vehicles matching "company"', async() => { + it('should return the vehicles matching "companyFk"', async() => { const company = await models.Company.findOne({where: {code: 'VNL'}}, options); ctx.args = {companyFk: company.id}; const searchResult = await models.Vehicle.filter(ctx, null, options); @@ -64,59 +64,64 @@ fdescribe('Vehicle filter()', () => { ctx.args = {warehouseFk: warehouse.id}; const searchResult = await models.Vehicle.filter(ctx); searchResult.forEach(record => { - expect(record.warehouseFk).toEqual(warehouse.id); + expect(record.warehouse).toEqual(warehouse.name); }); }); - // it('should return the vehicles matching "chassis"', async() => { - // const ctx = { - // args: { - // chassis: 'CH12345', - // } - // }; + it('should return the vehicles matching "chassis"', async() => { + const {chassis} = await models.Vehicle.findById(1, null, options); + ctx.args = {chassis}; + const [searchResult] = await models.Vehicle.filter(ctx); - // const result = await models.Vehicle.filter(ctx); + expect(searchResult.chassis).toEqual(chassis); + }); - // expect(result.length).toBeGreaterThan(0); - // expect(result[0].chassis).toEqual('CH12345'); - // }); + it('should return the vehicles matching "leasing"', async() => { + const leasing = 'Wayne leasing'; + ctx.args = {leasing}; + const searchResult = await models.Vehicle.filter(ctx); + searchResult.forEach(record => { + expect(record.leasing).toEqual(leasing); + }); + }); - // it('should return the vehicles matching "leasing"', async() => { - // const ctx = { - // args: { - // leasing: 'LeasingCompany', - // } - // }; + it('should return the vehicles matching "countryCodeFk"', async() => { + const countryCodeFk = 'ES'; + ctx.args = {countryCodeFk}; - // const result = await models.Vehicle.filter(ctx); + const searchResult = await models.Vehicle.filter(ctx); + searchResult.forEach(record => { + expect(record.countryCodeFk).toEqual(countryCodeFk); + }); + }); - // expect(result.length).toBeGreaterThan(0); - // expect(result[0].leasing).toEqual('LeasingCompany'); - // }); + it('should return the vehicles matching "vehicleTypeFk"', async() => { + const {name, id} = await models.VehicleType.findById(1, null, options); + ctx.args = {vehicleTypeFk: id}; - // it('should return the vehicles matching "countryCodeFk"', async() => { - // const ctx = { - // args: { - // countryCodeFk: 'US', - // } - // }; + const searchResult = await models.Vehicle.filter(ctx); + searchResult.forEach(record => { + expect(record.type).toEqual(name); + }); + }); - // const result = await models.Vehicle.filter(ctx); + it('should return the vehicles matching "vehicleStateFk"', async() => { + const {state, id} = await models.VehicleState.findById(3); + ctx.args = {vehicleStateFk: id}; - // expect(result.length).toBeGreaterThan(0); - // expect(result[0].countryCodeFk).toEqual('US'); - // }); + const searchResult = await models.Vehicle.filter(ctx); + searchResult.forEach(record => { + expect(record.state).toEqual(state); + }); + }); - // it('should return the vehicles matching "vehicleTypeFk"', async() => { - // const ctx = { - // args: { - // vehicleTypeFk: 3, - // } - // }; + it('should return the vehicles matching "description"', async() => { + const {description} = await models.Vehicle.findById(2); + ctx.args = {description}; - // const result = await models.Vehicle.filter(ctx); - - // expect(result.length).toBeGreaterThan(0); - // expect(result[0].vehicleTypeFk).toEqual(3); - // }); + const searchResult = await models.Vehicle.filter(ctx); + searchResult.forEach(record => { + expect(record.description).toEqual(description); + }); + }); }); -- 2.40.1 From fb653c1eca52d3563e5d31d04283d4b28ec7363a Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 24 Jan 2025 16:42:10 +0100 Subject: [PATCH 20/22] fix: refs #7119 rollback --- modules/route/back/methods/vehicle/filter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index fa0b84758..ef87c1448 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -71,6 +71,8 @@ module.exports = Self => { return /^\d+$/.test(value) ? {'v.id': value} : {numberPlate: {like: `%${value}%`}}; + case 'id': + return {'v.id': value}; case 'description': case 'tradeMark': case 'numberPlate': -- 2.40.1 From 051c6ffcbc7649e63e3d866d6da4c7f34f20db3e Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 28 Jan 2025 12:23:24 +0100 Subject: [PATCH 21/22] refactor(vehicle filter): refs #7119 simplify search condition to use logical OR for ID and number plate --- modules/route/back/methods/vehicle/filter.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index ef87c1448..cb55f5f3c 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -68,9 +68,7 @@ module.exports = Self => { const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'search': - return /^\d+$/.test(value) - ? {'v.id': value} - : {numberPlate: {like: `%${value}%`}}; + return {or: [{'v.id': value}, {numberPlate: {like: `%${value}%`}}]}; case 'id': return {'v.id': value}; case 'description': -- 2.40.1 From 77623b489bbd8d3c4c56afc472ddca86dc05ab0a Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 30 Jan 2025 10:55:36 +0100 Subject: [PATCH 22/22] feat: refs #7119 add new vehicle --- db/dump/fixtures.before.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 695347d61..c409eb692 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -863,7 +863,8 @@ INSERT INTO `vn`.`vehicle`(`id`, `numberPlate`, `tradeMark`, `model`, `companyFk (3, '2222-IMK', 'STARK INDUSTRIES', 'MARK-VI', 442, 1, 'Iron-Man Heavy Armor MARK-VI', 16, 1, 1, '', '', 442, 2, null), (4, '3333-IMK', 'STARK INDUSTRIES', 'MARK-VII', 442, 1, 'Iron-Man Heavy Armor MARK-VII', 14, 1, 1, '', '', 442, 3, null), (5, '4444-IMK', 'STARK INDUSTRIES', 'MARK-XLII', 442, 1, 'Iron-Man Heavy Armor MARK-XLII', 13, 1, 1, '', '', 442, 4, null), - (6, '5555-IMK', 'STARK INDUSTRIES', 'MARK-XLV', 442, 1, 'Iron-Man Heavy Armor MARK-XLV', 12, 0, 1, '', '', 442, 5, null); + (6, '5555-IMK', 'STARK INDUSTRIES', 'MARK-XLV', 442, 1, 'Iron-Man Heavy Armor MARK-XLV', 12, 0, 1, '', '', 442, 5, null), + (7, '5555-SHI', 'SHIELD', 'Quinjet', 442, 1, 'High-speed jet used by the Avengers', 30, 1, 1, 'QJ12345', 'SHIELD leasing', 1, 1, 1); INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, `inventoried`) VALUES -- 2.40.1