salix/services/loopback/common/methods/client/listWorkers.js

31 lines
855 B
JavaScript
Raw Normal View History

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.name), "")) \`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.name ASC`;
return Self.rawSql(query);
};
};