endpoint ListadoTrabajadores

This commit is contained in:
Vicente Falco 2017-06-30 09:26:55 +02:00
parent f4a4b7b45f
commit e3e7c9f863
5 changed files with 38 additions and 1 deletions

2
.vscode/launch.json vendored
View File

@ -5,7 +5,7 @@
"name": "Iniciar",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/app.js",
"program": "${workspaceRoot}/services/client/server/server.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",

5
component-config.json Normal file
View File

@ -0,0 +1,5 @@
{
"loopback-component-explorer": {
"mountPath": "/explorer"
}
}

View File

@ -0,0 +1,30 @@
module.exports = function(Client){
Client.remoteMethod('employeeList', {
description: 'List employee',
accessType: 'READ',
returns: {
arg: 'data',
type: 'Employee',
root: true
},
http: {
path: `/employeeList`,
verb: 'get'
}
});
Client.employeeList = function(cb) {
var include = {include: { relation: 'user'}, where: { userFk: { neq: null }}};
Client.app.models.Employee.find(include, function(err, instances) {
(err) ? cb(err, null) : cb(null, generateEmployees(instances));
});
};
function generateEmployees(instances){
var emps = [];
instances.forEach(function(e) {
emps.push({id: e.id, name: e.user().name});
}, this);
return emps;
}
}

View File

@ -10,6 +10,7 @@ module.exports = function(Client) {
require('../methods/client/addresses.js')(Client);
require('../methods/client/filter.js')(Client);
require('../methods/client/before-save.js')(Client);
require('../methods/client/employee.js')(Client);
// Validations

View File

@ -25,6 +25,7 @@ app.start = function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);