31 lines
863 B
JavaScript
31 lines
863 B
JavaScript
module.exports = function(Self) {
|
|
Self.remoteMethod('listWorkers', {
|
|
description: 'List workers',
|
|
accessType: 'READ',
|
|
returns: {
|
|
arg: 'data',
|
|
type: 'Worker',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/listWorkers`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.listWorkers = function() {
|
|
let query =
|
|
`SELECT w.id,
|
|
CONCAT(w.firstName, IFNULL(CONCAT(" ", w.lastName), "")) \`name\`
|
|
FROM worker w
|
|
JOIN account.user u ON w.userFk = u.id
|
|
JOIN account.roleRole rr ON rr.role = u.role
|
|
JOIN account.role r ON r.id = rr.inheritsFrom
|
|
WHERE u.active
|
|
AND r.\`name\` = 'employee'
|
|
ORDER BY w.lastName ASC`;
|
|
|
|
return Self.rawSql(query);
|
|
};
|
|
};
|