5244-component_workerAutocomplete #1679

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

View File

@ -17,12 +17,11 @@
<vn-autocomplete <vn-autocomplete
vn-one vn-one
ng-model="filter.buyerId" ng-model="filter.buyerId"
url="Workers/activeWithRole" url="TicketRequests/getItemTypeWorker"
search-function="{firstName: $search}" search-function="{firstName: $search}"
show-field="nickname"
value-field="id" value-field="id"
where="{role: {inq: ['logistic', 'buyer']}}"
label="Buyer"> label="Buyer">
<tpl-item>{{nickname}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>

View File

@ -54,11 +54,10 @@
vn-id="salesPerson" vn-id="salesPerson"
disabled="false" disabled="false"
ng-model="$ctrl.filter.salesPersonFk" ng-model="$ctrl.filter.salesPersonFk"
url="Workers/activeWithRole" url="TicketRequests/getItemTypeWorker"
show-field="nickname" show-field="nickname"
search-function="{firstName: $search}" search-function="{firstName: $search}"
value-field="id" value-field="id"
where="{role: {inq: ['logistic', 'buyer']}}"
label="Buyer" label="Buyer"
on-change="$ctrl.addFilters()"> on-change="$ctrl.addFilters()">
</vn-autocomplete> </vn-autocomplete>

View File

@ -54,11 +54,10 @@
vn-id="buyer" vn-id="buyer"
disabled="false" disabled="false"
ng-model="$ctrl.filter.buyerFk" ng-model="$ctrl.filter.buyerFk"
url="Workers/activeWithRole" url="TicketRequests/getItemTypeWorker"
show-field="nickname" show-field="nickname"
search-function="{firstName: $search}" search-function="{firstName: $search}"
value-field="id" value-field="id"
where="{role: {inq: ['logistic', 'buyer']}}"
label="Buyer" label="Buyer"
on-change="$ctrl.addFilters()"> on-change="$ctrl.addFilters()">
</vn-autocomplete> </vn-autocomplete>

View File

@ -44,8 +44,7 @@ class Controller extends Section {
{ {
field: 'buyerFk', field: 'buyerFk',
autocomplete: { autocomplete: {
url: 'Workers/activeWithRole', url: 'TicketRequests/getItemTypeWorker',
where: `{role: {inq: ['logistic', 'buyer']}}`,
searchFunction: '{firstName: $search}', searchFunction: '{firstName: $search}',
showField: 'nickname', showField: 'nickname',
valueField: 'id', valueField: 'id',

View File

@ -22,12 +22,11 @@
<vn-autocomplete <vn-autocomplete
vn-one vn-one
ng-model="filter.attenderFk" ng-model="filter.attenderFk"
url="Workers/activeWithRole" url="TicketRequests/getItemTypeWorker"
search-function="{firstName: $search}" search-function="{firstName: $search}"
show-field="nickname"
value-field="id" value-field="id"
where="{role: {inq: ['logistic', 'buyer']}}"
label="Atender"> label="Atender">
<tpl-item>{{nickname}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal class="vn-px-lg"> <vn-horizontal class="vn-px-lg">

View File

@ -17,12 +17,11 @@
<vn-autocomplete <vn-autocomplete
vn-one vn-one
ng-model="filter.buyerId" ng-model="filter.buyerId"
url="Workers/activeWithRole" url="TicketRequests/getItemTypeWorker"
search-function="{firstName: $search}" search-function="{firstName: $search}"
show-field="nickname"
value-field="id" value-field="id"
where="{role: {inq: ['logistic', 'buyer']}}"
label="Buyer"> label="Buyer">
<tpl-item>{{nickname}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>

View File

@ -1,7 +1,9 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; 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 => { module.exports = Self => {
Self.remoteMethodCtx('getItemTypeWorker', { Self.remoteMethod('getItemTypeWorker', {
description: 'Returns the workers that appear in itemType', description: 'Returns the workers that appear in itemType',
accessType: 'READ', accessType: 'READ',
accepts: [{ accepts: [{
@ -20,10 +22,9 @@ module.exports = Self => {
} }
}); });
Self.getItemTypeWorker = async(ctx, filter, options) => { Self.getItemTypeWorker = async(filter, options) => {
const myOptions = {}; const myOptions = {};
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
let tx;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -33,25 +34,29 @@ module.exports = Self => {
FROM itemType it FROM itemType it
JOIN worker w ON w.id = it.workerFk JOIN worker w ON w.id = it.workerFk
JOIN account.user u ON u.id = w.id`; JOIN account.user u ON u.id = w.id`;
const stmt = new ParameterizedSQL(query);
let stmt = new ParameterizedSQL(query); filter.where = buildFilter(filter.where, (param, value) => {
switch (param) {
if (filter.where) { case 'firstName':
const value = filter.where.firstName; return {or: [
const myFilter = {
where: {or: [
{'w.firstName': {like: `%${value}%`}}, {'w.firstName': {like: `%${value}%`}},
{'w.lastName': {like: `%${value}%`}}, {'w.lastName': {like: `%${value}%`}},
{'u.name': {like: `%${value}%`}}, {'u.name': {like: `%${value}%`}},
{'u.nickname': {like: `%${value}%`}} {'u.nickname': {like: `%${value}%`}}
]} ]};
case 'id':
return {'w.id': value};
}
});
let myFilter = {
where: {'u.active': true}
}; };
myFilter = mergeFilters(myFilter, filter);
stmt.merge(conn.makeSuffix(myFilter)); stmt.merge(conn.makeSuffix(myFilter));
}
if (tx) await tx.commit();
return conn.executeStmt(stmt); return conn.executeStmt(stmt);
}; };
}; };