endpoint ListadoTrabajadores
This commit is contained in:
parent
f4a4b7b45f
commit
e3e7c9f863
|
@ -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}",
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"loopback-component-explorer": {
|
||||
"mountPath": "/explorer"
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue