Client Service: Employee List active
This commit is contained in:
parent
2eeae6cc36
commit
ac8797f24d
|
@ -13,20 +13,30 @@ module.exports = function(Client) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Client.employeeList = function(cb) {
|
let getEmployees = listEmployees => {
|
||||||
var include = {include: {relation: 'user'}, where: {userFk: {neq: null}}};
|
let employees = [];
|
||||||
Client.app.models.Employee.find(include, function(err, instances) {
|
listEmployees.forEach(function(e) {
|
||||||
if (err)
|
employees.push({id: e.id, name: e.name});
|
||||||
cb(err, null);
|
}, this);
|
||||||
cb(null, generateEmployees(instances));
|
return employees;
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function generateEmployees(instances) {
|
Client.employeeList = function(callback) {
|
||||||
var emps = [];
|
let query = `SELECT em.id, CASE em.surname WHEN NULL THEN em.name ELSE concat(em.name, " ", em.surname) END \`name\`
|
||||||
instances.forEach(function(e) {
|
FROM Employee em
|
||||||
emps.push({id: e.id, name: e.user().name});
|
JOIN Account ac ON em.userFk = ac.id
|
||||||
}, this);
|
JOIN RoleMapping rm on ac.id=rm.principalId
|
||||||
return emps;
|
JOIN Role rl on rm.roleId = rl.id
|
||||||
}
|
WHERE ac.active
|
||||||
|
and rl.\`name\`='employee'
|
||||||
|
ORDER BY em.name ASC`;
|
||||||
|
|
||||||
|
Client.rawSql(query, [], callback)
|
||||||
|
.then(response => {
|
||||||
|
callback(null, getEmployees(response));
|
||||||
|
})
|
||||||
|
.catch(reject => {
|
||||||
|
callback(reject, null);
|
||||||
|
});
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,6 @@ module.exports = function(Ticket) {
|
||||||
path: '/:time/changeTime'
|
path: '/:time/changeTime'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ticket.changeTime = function(ctx, time, cb) {
|
Ticket.changeTime = function(ctx, time, cb) {
|
||||||
var tickets = ctx.req.body.tickets;
|
var tickets = ctx.req.body.tickets;
|
||||||
var FakeProduction = Ticket.app.models.FakeProduction;
|
var FakeProduction = Ticket.app.models.FakeProduction;
|
||||||
|
@ -25,15 +24,14 @@ module.exports = function(Ticket) {
|
||||||
|
|
||||||
var query = `update Ticket set date = CONCAT(DATE(date), ' ', ?) where id in (?)`;
|
var query = `update Ticket set date = CONCAT(DATE(date), ' ', ?) where id in (?)`;
|
||||||
var params = [hour, tickets];
|
var params = [hour, tickets];
|
||||||
|
|
||||||
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {hour: hour}, function(err, res){
|
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {hour: hour}, function(err, res){
|
||||||
if(err)
|
if (err)
|
||||||
cb(err, null)
|
cb(err, null);
|
||||||
else
|
else
|
||||||
Ticket.rawSql(query, params, cb).then(function(response) {
|
Ticket.rawSql(query, params, cb).then(function(response) {
|
||||||
cb(null, response);
|
cb(null, response);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@ module.exports = function(Ticket) {
|
||||||
required: true,
|
required: true,
|
||||||
description: 'worker id',
|
description: 'worker id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
arg: 'response',
|
arg: 'response',
|
||||||
|
@ -25,12 +25,11 @@ module.exports = function(Ticket) {
|
||||||
changeWorker(worker, tickets, cb);
|
changeWorker(worker, tickets, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
var changeWorker = function(worker, tickets, cb){
|
let changeWorker = function(worker, tickets, cb) {
|
||||||
var inserts = [];
|
|
||||||
var FakeProduction = Ticket.app.models.FakeProduction;
|
var FakeProduction = Ticket.app.models.FakeProduction;
|
||||||
|
|
||||||
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {workerFk: worker}, function(err, info){
|
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {workerFk: worker}, function(err, info){
|
||||||
(err) ? cb(err, null) : cb(null, info);
|
(err) ? cb(err, null) : cb(null, info);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module.exports = function(Ticket) {
|
module.exports = function(Ticket) {
|
||||||
Ticket.remoteMethod('list', {
|
Ticket.remoteMethod('list', {
|
||||||
description: 'List tickets for production',
|
description: 'List tickets for production',
|
||||||
/*accepts: {
|
/* accepts: {
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -19,7 +19,7 @@ module.exports = function(Ticket) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Ticket.list = function(cb) {
|
Ticket.list = function(cb) {
|
||||||
//list();
|
// list();
|
||||||
};
|
};
|
||||||
|
|
||||||
var list = function(){
|
var list = function(){
|
||||||
|
@ -27,11 +27,11 @@ module.exports = function(Ticket) {
|
||||||
|
|
||||||
var query = "CALL production_control_source(?, ?)"
|
var query = "CALL production_control_source(?, ?)"
|
||||||
|
|
||||||
var cb = function(error, res){
|
var cb = function(error, res) {
|
||||||
if(error) console.log(error);
|
if (error) console.log(error);
|
||||||
else console.log(res);
|
else console.log(res);
|
||||||
};
|
};
|
||||||
|
|
||||||
Ticket.rawSql(query, params, cb);
|
Ticket.rawSql(query, params, cb);
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
var vnLoopback = require('../../loopback/server/server.js');
|
var vnLoopback = require('../../loopback/server/server.js');
|
||||||
|
|
||||||
var app = module.exports = vnLoopback.loopback();
|
var app = module.exports = vnLoopback.loopback();
|
||||||
|
|
Loading…
Reference in New Issue