salix/services/route/common/methods/comboVehicles.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

module.exports = (Vehicle) => {
Vehicle.remoteMethod('comboVehicles', {
description: 'returns list of vehicles',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'Object',
required: false,
description: 'Filter defining where and paginated data',
http: {source: 'query'}
}],
returns: {
arg: 'data',
type: 'Vehicle',
root: true
},
http: {
path: `/comboVehicles`,
verb: 'get'
}
});
Vehicle.comboVehicles = (filter, callback) => {
Vehicle.find(filter, (_, instances) => {
callback(null, formatOutput(instances));
});
};
function formatOutput(instances) {
let results = [];
for (let instance of instances) {
let numberPlate = ` ${instance.numberPlate}` || '';
results.push({
id: instance.id,
name: `${instance.tradeMark} ${instance.model}${numberPlate}`
});
}
return results;
}
};