5244-component_workerAutocomplete #1679
|
@ -4,25 +4,35 @@ import Autocomplete from '../autocomplete';
|
|||
export default class WorkerAutocomplete extends Autocomplete {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
let url = 'Workers/search';
|
||||
if (this.departments) {
|
||||
const parameter = encodeURIComponent(JSON.stringify(this.departments));
|
||||
url = `Workers/search?departmentCodes=${parameter}`;
|
||||
}
|
||||
Object.assign(this, {
|
||||
label: 'Worker',
|
||||
url: 'Workers/search',
|
||||
fields: ['id', 'name', 'nickname'],
|
||||
url: url,
|
||||
searchFunction: function({$search}) {
|
||||
return {and: [
|
||||
vicent marked this conversation as resolved
Outdated
|
||||
{active: {neq: false}},
|
||||
{'u.active': {neq: false}},
|
||||
{or: [
|
||||
{name: $search},
|
||||
{nickname: {like: '%' + $search + '%'}},
|
||||
{code: {like: $search + '%'}}
|
||||
{'u.name': $search},
|
||||
{'u.nickname': {like: '%' + $search + '%'}},
|
||||
{'w.code': {like: $search + '%'}}
|
||||
]}
|
||||
]};
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnWorkerAutocomplete', {
|
||||
slotTemplate: require('./index.html'),
|
||||
controller: WorkerAutocomplete
|
||||
controller: WorkerAutocomplete,
|
||||
bindings: {
|
||||
departments: '<?'
|
||||
},
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<vn-worker-autocomplete
|
||||
vn-one
|
||||
ng-model="$ctrl.workerFk"
|
||||
where="{role: 'employee'}">
|
||||
departments="['VN']">
|
||||
</vn-worker-autocomplete>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('search', {
|
||||
Self.remoteMethodCtx('search', {
|
||||
description: 'Returns an array of search from an specified worker',
|
||||
vicent marked this conversation as resolved
Outdated
jgallego
commented
chatGPT: No, esa frase tiene algunos errores gramaticales y no es completamente clara en inglés. Si intentas decir que quieres devolver un arreglo de resultados de búsqueda de un trabajador específico, la frase correcta sería: "Returns an array of search results for a specified worker." Esa corrección asume que estás hablando de devolver resultados de búsqueda relacionados con un trabajador en particular. chatGPT: No, esa frase tiene algunos errores gramaticales y no es completamente clara en inglés.
Si intentas decir que quieres devolver un arreglo de resultados de búsqueda de un trabajador específico, la frase correcta sería:
"Returns an array of search results for a specified worker."
Esa corrección asume que estás hablando de devolver resultados de búsqueda relacionados con un trabajador en particular.
|
||||
accepts: [{
|
||||
arg: 'filter',
|
||||
type: 'Object',
|
||||
type: 'object',
|
||||
description: 'Filter defining where and paginated data',
|
||||
vicent marked this conversation as resolved
Outdated
jgallego
commented
Filter to define conditions and paginate the data. Filter to define conditions and paginate the data.
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'departmentCodes',
|
||||
type: ['string'],
|
||||
description: 'Department codes to search workers',
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
|
@ -17,24 +25,39 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.search = async filter => {
|
||||
const $ = Self.app.models;
|
||||
Self.search = async(ctx, filter, departmentCodes) => {
|
||||
const models = Self.app.models;
|
||||
const conn = Self.dataSource.connector;
|
||||
|
||||
let {where} = filter;
|
||||
const users = where && await $.VnUser.find({
|
||||
fields: ['id'],
|
||||
where
|
||||
});
|
||||
let allDepartments = [];
|
||||
if (departmentCodes) {
|
||||
const departments = await models.Department.find({
|
||||
fields: ['id'],
|
||||
where: {code: {inq: departmentCodes}}
|
||||
});
|
||||
const departmentIds = departments.map(department => department.id);
|
||||
|
||||
const workers = await Self.find({
|
||||
fields: ['id'],
|
||||
where: {
|
||||
businessFk: {neq: null},
|
||||
id: users ? {inq: users.map(u => u.id)} : undefined
|
||||
let departmentLeaves = [];
|
||||
for (let id of departmentIds) {
|
||||
const leaves = await models.Department.getLeaves(ctx, id, null);
|
||||
console.log(leaves);
|
||||
for (let leave of leaves) departmentLeaves.push(leave.id);
|
||||
}
|
||||
});
|
||||
|
||||
where = {id: {inq: workers.map(w => w.id)}};
|
||||
return await $.VnUser.find(Object.assign({}, filter, {where}));
|
||||
allDepartments = departmentIds.concat(departmentLeaves);
|
||||
console.log(allDepartments);
|
||||
const where = {'d.id': {inq: allDepartments}};
|
||||
filter = mergeFilters(filter, {where});
|
||||
}
|
||||
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT DISTINCT w.code, u.name, u.nickname
|
||||
FROM worker w
|
||||
JOIN account.user u ON u.id = w.id
|
||||
JOIN business b ON b.workerFk = w.id
|
||||
JOIN department d ON d.id = b.departmentFk`);
|
||||
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
return conn.executeStmt(stmt);
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
url,