Merge branch 'dev' into hotfix_workCenter_isNull
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-07-31 08:54:37 +00:00
commit db992a9b91
7 changed files with 34 additions and 104 deletions

View File

@ -1,44 +0,0 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('activeBuyers', {
description: 'Returns a list of buyers for the given item type',
accepts: [{
arg: 'filter',
type: 'object',
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/activeBuyers`,
verb: 'GET'
}
});
Self.activeBuyers = async(filter, options) => {
const conn = Self.dataSource.connector;
const where = {isActive: true};
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
filter = mergeFilters(filter, {where});
let stmt = new ParameterizedSQL(
`SELECT DISTINCT w.id workerFk, w.firstName, w.lastName, u.name, u.nickname
FROM worker w
JOIN itemType it ON it.workerFk = w.id
JOIN account.user u ON u.id = w.id
JOIN item i ON i.typeFk = it.id`,
null, myOptions);
stmt.merge(conn.makeSuffix(filter));
return conn.executeStmt(stmt);
};
};

View File

@ -1,24 +0,0 @@
const models = require('vn-loopback/server/server').models;
describe('Worker activeBuyers', () => {
it('should return the buyers in itemType as result', async() => {
const tx = await models.Item.beginTransaction({});
try {
const options = {transaction: tx};
const filter = {};
const result = await models.Item.activeBuyers(filter, options);
const firstWorker = result[0];
const secondWorker = result[1];
expect(result.length).toEqual(2);
expect(firstWorker.nickname).toEqual('logisticBossNick');
expect(secondWorker.nickname).toEqual('buyerNick');
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -14,7 +14,6 @@ module.exports = Self => {
require('../methods/item/getWasteByWorker')(Self); require('../methods/item/getWasteByWorker')(Self);
require('../methods/item/getWasteByItem')(Self); require('../methods/item/getWasteByItem')(Self);
require('../methods/item/createIntrastat')(Self); require('../methods/item/createIntrastat')(Self);
require('../methods/item/activeBuyers')(Self);
require('../methods/item/buyerWasteEmail')(Self); require('../methods/item/buyerWasteEmail')(Self);
require('../methods/item/labelPdf')(Self); require('../methods/item/labelPdf')(Self);

View File

@ -26,7 +26,7 @@
search-function="{firstName: $search}" search-function="{firstName: $search}"
value-field="id" value-field="id"
where="{role: {inq: ['logistic', 'buyer']}}" where="{role: {inq: ['logistic', 'buyer']}}"
label="Atender"> label="Buyer">
<tpl-item>{{nickname}}</tpl-item> <tpl-item>{{nickname}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>

View File

@ -41,10 +41,10 @@
<vn-autocomplete <vn-autocomplete
vn-one vn-one
ng-model="filter.buyerFk" ng-model="filter.buyerFk"
url="Items/activeBuyers" url="TicketRequests/getItemTypeWorker"
search-function="{firstName: $search}"
show-field="nickname" show-field="nickname"
search-function="{nickname: {like: '%'+ $search +'%'}}" value-field="id"
value-field="workerFk"
label="Buyer"> label="Buyer">
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete <vn-autocomplete

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,38 +22,37 @@ module.exports = Self => {
} }
}); });
Self.getItemTypeWorker = async(ctx, filter, options) => { Self.getItemTypeWorker = async filter => {
const myOptions = {};
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = const query =
`SELECT DISTINCT u.id, u.nickname `SELECT DISTINCT u.id, u.nickname
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};
}
});
stmt.merge(conn.makeSuffix(myFilter)); let myFilter = {
} where: {'u.active': true}
};
if (tx) await tx.commit(); myFilter = mergeFilters(myFilter, filter);
stmt.merge(conn.makeSuffix(myFilter));
return conn.executeStmt(stmt); return conn.executeStmt(stmt);
}; };
}; };

View File

@ -1,12 +1,10 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('ticket-request getItemTypeWorker()', () => { describe('ticket-request getItemTypeWorker()', () => {
const ctx = {req: {accessToken: {userId: 18}}};
it('should return the buyer as result', async() => { it('should return the buyer as result', async() => {
const filter = {where: {firstName: 'buyer'}}; const filter = {where: {firstName: 'buyer'}};
const result = await models.TicketRequest.getItemTypeWorker(ctx, filter); const result = await models.TicketRequest.getItemTypeWorker(filter);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
}); });
@ -14,7 +12,7 @@ describe('ticket-request getItemTypeWorker()', () => {
it('should return the workers at itemType as result', async() => { it('should return the workers at itemType as result', async() => {
const filter = {}; const filter = {};
const result = await models.TicketRequest.getItemTypeWorker(ctx, filter); const result = await models.TicketRequest.getItemTypeWorker(filter);
expect(result.length).toBeGreaterThan(1); expect(result.length).toBeGreaterThan(1);
}); });