[finish] active salesPerson service
This commit is contained in:
parent
4eeb5df74f
commit
fbd5fea126
|
@ -24,7 +24,7 @@
|
||||||
<vn-autocomplete vn-one
|
<vn-autocomplete vn-one
|
||||||
initial-data="$ctrl.client.salesPerson"
|
initial-data="$ctrl.client.salesPerson"
|
||||||
field="$ctrl.client.salesPersonFk"
|
field="$ctrl.client.salesPersonFk"
|
||||||
url="/client/api/Employees"
|
url="/client/api/Clients/activeSalesPerson"
|
||||||
show-field="name"
|
show-field="name"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
select-fields="surname"
|
select-fields="surname"
|
||||||
|
|
|
@ -22,23 +22,41 @@ module.exports = (Client) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Client.activeSalesPerson = (filter, callback) => {
|
Client.activeSalesPerson = (filter, callback) => {
|
||||||
var filter = filter || {};
|
let skip = filter.skip || 0;
|
||||||
|
let limit = filter.limit || 10;
|
||||||
|
let where = getCondition(filter.where);
|
||||||
|
|
||||||
filter.include = [
|
let query = `SELECT em.id, em.name, em.surname FROM Employee em
|
||||||
{
|
JOIN Account ac ON em.userFk = ac.id
|
||||||
"relation": "role",
|
JOIN Role ON Role.id = ac.roleFK
|
||||||
"scope": {
|
WHERE ac.active AND Role.\`name\`='salesPerson' ${where}
|
||||||
"fields": ["name"]
|
ORDER BY em.name ASC
|
||||||
}
|
LIMIT ${limit} OFFSET ${skip}`;
|
||||||
},
|
|
||||||
{
|
Client.rawSql(query, [], callback)
|
||||||
"relation": 'user'
|
.then(response => {
|
||||||
}];
|
callback(null, response);
|
||||||
console.log(filter);
|
})
|
||||||
Client.app.models.Employee.find(filter, (err, instances) => {
|
.catch(reject => {
|
||||||
if (err)
|
callback(reject, null);
|
||||||
callback(err, null);
|
|
||||||
callback(null, instances);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getCondition(where) {
|
||||||
|
let out = [];
|
||||||
|
|
||||||
|
if(typeof where === 'object') {
|
||||||
|
Object.keys(where).forEach((k) => {
|
||||||
|
let value = where[k];
|
||||||
|
if(typeof value !== 'object') {
|
||||||
|
out.push(`em.${k}='${value}'`);
|
||||||
|
} else {
|
||||||
|
let firstProperty = Object.keys(value)[0];
|
||||||
|
out.push(`em.${k} ${firstProperty} '${value[firstProperty]}'`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.length ? 'AND ' + out.join(' AND ') : '';
|
||||||
|
}
|
||||||
};
|
};
|
|
@ -13,6 +13,7 @@ module.exports = function(Client) {
|
||||||
require('../methods/client/employee.js')(Client);
|
require('../methods/client/employee.js')(Client);
|
||||||
require('../methods/client/filter.js')(Client);
|
require('../methods/client/filter.js')(Client);
|
||||||
require('../methods/client/roles.js')(Client);
|
require('../methods/client/roles.js')(Client);
|
||||||
|
require('../methods/client/salesperson.js')(Client);
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue