2023-04-20 06:23:46 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('getVehiclesSorted', {
|
2023-04-20 08:20:15 +00:00
|
|
|
description: 'Sort the vehicles by warehouse',
|
2023-04-20 06:23:46 +00:00
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'warehouseFk',
|
|
|
|
type: 'number'
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getVehiclesSorted`,
|
|
|
|
verb: `POST`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.getVehiclesSorted = async warehouseFk => {
|
|
|
|
const vehicles = await Self.rawSql(`
|
2023-05-29 10:42:27 +00:00
|
|
|
SELECT ROW_NUMBER() OVER (ORDER BY v.warehouseFk = ? DESC, w.id, v.numberPlate) AS 'order',
|
|
|
|
v.id,
|
|
|
|
v.warehouseFk,
|
|
|
|
CONCAT(v.numberPlate, ' - ', w.name) as description
|
2023-04-20 06:23:46 +00:00
|
|
|
FROM vehicle v
|
2023-05-29 10:42:27 +00:00
|
|
|
JOIN warehouse w ON w.id = v.warehouseFk
|
|
|
|
ORDER BY v.warehouseFk = ? DESC, w.id, v.numberPlate ASC`, [warehouseFk, warehouseFk]);
|
2023-04-20 06:23:46 +00:00
|
|
|
return vehicles;
|
|
|
|
};
|
|
|
|
};
|