5244-component_workerAutocomplete #1679

Merged
vicent merged 33 commits from 5244-component_workerAutocomplete into dev 2023-08-25 08:56:46 +00:00
1 changed files with 0 additions and 65 deletions
Showing only changes of commit d6a27741b5 - Show all commits

View File

@ -1,65 +0,0 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('getItemTypeWorker', {
description: 'Returns the workers that appear in itemType',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'Object',
description: 'Filter defining where and paginated data',
required: true
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/getItemTypeWorker`,
verb: 'GET'
}
});
Self.getItemTypeWorker = async(filter, options) => {
const myOptions = {};
const conn = Self.dataSource.connector;
if (typeof options == 'object')
Object.assign(myOptions, options);
const query =
`SELECT DISTINCT u.id, w.firstName, w.lastName, u.nickname, u.name
FROM itemType it
JOIN worker w ON w.id = it.workerFk
JOIN account.user u ON u.id = w.id`;
let stmt = new ParameterizedSQL(query);
let clientFilter = Object.assign({}, filter);
clientFilter.where = buildFilter(filter.where, (param, value) => {
switch (param) {
case 'role':
return {'r.name': value};
case 'firstName':
return {or: [
{'w.firstName': {like: `%${value}%`}},
{'w.lastName': {like: `%${value}%`}},
{'u.name': {like: `%${value}%`}},
{'u.nickname': {like: `%${value}%`}}
]};
case 'id':
return {'w.id': value};
}
});
let myFilter = {
where: {'u.active': true}
};
myFilter = mergeFilters(myFilter, clientFilter);
stmt.merge(conn.makeSuffix(myFilter));
return conn.executeStmt(stmt);
};
};