feat: refs #7119 add VehicleEvent and VehicleState models with associated methods and SQL fixtures
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
086b7aed4b
commit
39fc196464
|
@ -849,14 +849,14 @@ INSERT INTO `vn`.`deliveryPoint` (`id`, `name`, `ubication`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'Gotham','1007 Mountain Drive, Gotham');
|
(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
|
VALUES
|
||||||
(1, '3333-BAT', 'WAYNE INDUSTRIES', 'BATMOBILE', 442, 1, 'The ultimate war machine', 50, 1, 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),
|
(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),
|
(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),
|
(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),
|
(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);
|
(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`)
|
INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, `inventoried`)
|
||||||
VALUES
|
VALUES
|
||||||
|
@ -4049,3 +4049,19 @@ INSERT IGNORE INTO vn.osrmConfig (id,url,tolerance)
|
||||||
INSERT IGNORE INTO vn.inventoryConfig
|
INSERT IGNORE INTO vn.inventoryConfig
|
||||||
SET id = 1,
|
SET id = 1,
|
||||||
supplierFk = 4;
|
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);
|
|
@ -0,0 +1,2 @@
|
||||||
|
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'delivery');
|
|
@ -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);
|
||||||
|
};
|
||||||
|
};
|
|
@ -35,6 +35,9 @@
|
||||||
"Vehicle": {
|
"Vehicle": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"VehicleEvent": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"VehicleState": {
|
"VehicleState": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/vehicle/sorted')(Self);
|
require('../methods/vehicle/sorted')(Self);
|
||||||
|
require('../methods/vehicle/filter')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"base": "VnModel",
|
"base": "VnModel",
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "vehicle"
|
"table": "vehicle"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -29,6 +29,15 @@
|
||||||
},
|
},
|
||||||
"isActive": {
|
"isActive": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"countryCodeFk": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"chassis": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"leasing": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
@ -46,14 +55,19 @@
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "DeliveryPoint",
|
"model": "DeliveryPoint",
|
||||||
"foreignKey": "deliveryPointFk"
|
"foreignKey": "deliveryPointFk"
|
||||||
|
},
|
||||||
|
"event": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "VehicleEvent",
|
||||||
|
"foreignKey": "id"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scope": {
|
"scope": {
|
||||||
"where": {
|
"where": {
|
||||||
"isActive": {
|
"isActive": {
|
||||||
"neq": false
|
"neq": false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"acls": [
|
"acls": [
|
||||||
{
|
{
|
||||||
|
@ -63,4 +77,4 @@
|
||||||
"permission": "ALLOW"
|
"permission": "ALLOW"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue