feat: refs #7119 add VehicleEvent and VehicleState models with associated methods and SQL fixtures
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-12-24 13:01:23 +01:00
parent 086b7aed4b
commit 39fc196464
7 changed files with 150 additions and 11 deletions

View File

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

View File

@ -0,0 +1,2 @@
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery');

View File

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

View File

@ -35,6 +35,9 @@
"Vehicle": {
"dataSource": "vn"
},
"VehicleEvent": {
"dataSource": "vn"
},
"VehicleState": {
"dataSource": "vn"
},

View File

@ -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"
}
]
}

View File

@ -1,3 +1,4 @@
module.exports = Self => {
require('../methods/vehicle/sorted')(Self);
require('../methods/vehicle/filter')(Self);
};

View File

@ -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"
}
]
}
}