diff --git a/client/client/src/basic-data/basic-data.html b/client/client/src/basic-data/basic-data.html
index b509fa7a47..07c60750e2 100644
--- a/client/client/src/basic-data/basic-data.html
+++ b/client/client/src/basic-data/basic-data.html
@@ -29,9 +29,6 @@
value-field="id"
select-fields="surname"
label="Salesperson">
-
- {{$parent.$parent.item.name}} {{$parent.$parent.item.surname}}
-
{
Client.remoteMethod('activeSalesPerson', {
description: 'returns actives employees with salesperson role',
accessType: 'READ',
- isStatic: true,
accepts: [{
arg: 'filter',
type: 'Object',
@@ -26,16 +25,17 @@ module.exports = (Client) => {
let limit = filter.limit || 10;
let where = getCondition(filter.where);
- let query = `SELECT em.id, em.name, em.surname FROM Employee em
+ let query = `SELECT em.id, em.name, em.surname
+ FROM Employee em
JOIN Account ac ON em.userFk = ac.id
JOIN Role ON Role.id = ac.roleFK
WHERE ac.active AND Role.\`name\`='salesPerson' ${where}
ORDER BY em.name ASC
LIMIT ${limit} OFFSET ${skip}`;
-
+
Client.rawSql(query, [], callback)
.then(response => {
- callback(null, response);
+ callback(null, formatSalesPerson(response));
})
.catch(reject => {
callback(reject, null);
@@ -44,19 +44,36 @@ module.exports = (Client) => {
function getCondition(where) {
let out = [];
-
if(typeof where === 'object') {
Object.keys(where).forEach((k) => {
let value = where[k];
- if(typeof value !== 'object') {
+ if (typeof value === 'number') {
+ out.push(`em.${k}=${value}`);
+ } else if (typeof value === 'string') {
out.push(`em.${k}='${value}'`);
- } else {
+ } else if (typeof value === 'boolean' || value === null) {
+ out.push(`em.${k} IS ${String(value).toUpperCase()}`);
+ } else if (Object.keys(value).length) {
let firstProperty = Object.keys(value)[0];
out.push(`em.${k} ${firstProperty} '${value[firstProperty]}'`);
+ } else {
+ throw new Error ('Error: unexpected type');
}
});
}
+ return out.length ? `AND (${out.join(' AND ')})` : '';
+ }
- return out.length ? 'AND ' + out.join(' AND ') : '';
+ function formatSalesPerson (response) {
+ let results = [];
+
+ response.forEach( person => {
+ results.push({
+ id: person.id,
+ name: `${person.name} ${person.surname}`
+ });
+ });
+
+ return results;
}
};
\ No newline at end of file