feat: refs #7119 add VehicleType model and update vehicle permissions for delivery roles
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2025-01-23 10:53:53 +01:00
parent 0440582e2b
commit 3ea67675da
5 changed files with 54 additions and 31 deletions

View File

@ -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);

View File

@ -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 (

View File

@ -47,6 +47,9 @@
"VehicleState": {
"dataSource": "vn"
},
"VehicleType": {
"dataSource": "vn"
},
"RoutesMonitor": {
"dataSource": "vn"
}

View File

@ -0,0 +1,19 @@
{
"name": "VehicleType",
"base": "VnModel",
"options": {
"mysql": {
"table": "vehicleType"
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string"
}
}
}

View File

@ -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": {