salix/modules/route/back/methods/vehicle/getVehiclesSorted.js

29 lines
771 B
JavaScript
Raw Normal View History

2023-04-20 06:23:46 +00:00
module.exports = Self => {
Self.remoteMethod('getVehiclesSorted', {
description: 'Sort the vehicles by a warehouse',
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(`
SELECT v.id, v.numberPlate, w.name
FROM vehicle v
JOIN warehouse w ON w.id = v.warehouseFk
ORDER BY v.warehouseFk = ? DESC, v.numberPlate ASC`, [warehouseFk]);
return vehicles;
};
};