active salesperson service in progress

This commit is contained in:
Dani Herrero 2017-09-27 07:22:40 +02:00
parent 235cc2d8f6
commit 43a55f60c4
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
module.exports = (Client) => {
Client.remoteMethod('activeSalesPerson', {
description: 'returns actives employees with salesperson role',
accessType: 'READ',
isStatic: true,
accepts: [{
arg: 'filter',
type: 'Object',
required: false,
description: 'Filter defining where and paginated data',
http: {source: 'query'}
}],
returns: {
arg: 'data',
type: 'Employee',
root: true
},
http: {
path: `/activeSalesPerson`,
verb: 'get'
}
});
Client.activeSalesPerson = (filter, callback) => {
var filter = filter || {};
filter.include = [
{
"relation": "role",
"scope": {
"fields": ["name"]
}
},
{
"relation": 'user'
}];
console.log(filter);
Client.app.models.Employee.find(filter, (err, instances) => {
if (err)
callback(err, null);
callback(null, instances);
});
};
};