2023-04-20 06:23:46 +00:00
|
|
|
module.exports = Self => {
|
2023-05-29 11:49:32 +00:00
|
|
|
Self.remoteMethod('sorted', {
|
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: {
|
2023-05-29 11:49:32 +00:00
|
|
|
path: `/sorted`,
|
2023-04-20 06:23:46 +00:00
|
|
|
verb: `POST`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-29 11:49:32 +00:00
|
|
|
Self.sorted = async warehouseFk => {
|
2023-05-30 10:21:44 +00:00
|
|
|
return Self.rawSql(`
|
2023-05-31 08:04:34 +00:00
|
|
|
SELECT v.id, v.warehouseFk, v.numberPlate, w.name
|
2023-05-30 10:21:44 +00:00
|
|
|
FROM vehicle v
|
|
|
|
JOIN warehouse w ON w.id = v.warehouseFk
|
|
|
|
ORDER BY v.warehouseFk = ? DESC, w.id, v.numberPlate ASC;
|
|
|
|
`, [warehouseFk]);
|
2023-04-20 06:23:46 +00:00
|
|
|
};
|
|
|
|
};
|