29 lines
771 B
JavaScript
29 lines
771 B
JavaScript
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;
|
|
};
|
|
};
|