diff --git a/services/client/common/methods/client/salesperson.js b/services/client/common/methods/client/salesperson.js new file mode 100644 index 000000000..8bf04e206 --- /dev/null +++ b/services/client/common/methods/client/salesperson.js @@ -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); + }); + }; +}; \ No newline at end of file