feat(item): back filter buyer in search panel ans test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e688e078ec
commit
5c7efbb838
|
@ -1,9 +1,9 @@
|
|||
DROP PROCEDURE IF EXISTS vn.item_getBalance;
|
||||
DROP PROCEDURE IF EXISTS `vn`.`item_getBalance`;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE
|
||||
definer = root@`%` procedure vn.item_getBalance(IN vItemId int, IN vWarehouse int)
|
||||
definer = root@`%` procedure `vn`.`item_getBalance`(IN vItemId int, IN vWarehouse int)
|
||||
BEGIN
|
||||
DECLARE vDateInventory DATETIME;
|
||||
DECLARE vCurdate DATE DEFAULT CURDATE();
|
||||
|
|
|
@ -739,7 +739,7 @@ INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `warehouseFk`, `
|
|||
(3, 'WPN', 'Paniculata', 2, 1, 31, 35, 0),
|
||||
(4, 'PRT', 'Delivery ports', 3, 1, NULL, 35, 1),
|
||||
(5, 'CON', 'Container', 3, 1, NULL, 35, 1),
|
||||
(6, 'ALS', 'Alstroemeria', 1, 1, 31, 35, 0);
|
||||
(6, 'ALS', 'Alstroemeria', 1, 1, 31, 16, 0);
|
||||
|
||||
INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`)
|
||||
VALUES
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
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.activeWorkers = async(query, filter) => {
|
||||
let conn = Self.dataSource.connector;
|
||||
if (filter.where && filter.where.and && Array.isArray(filter.where.and)) {
|
||||
let where = {};
|
||||
filter.where.and.forEach(element => {
|
||||
where[Object.keys(element)[0]] = Object.values(element)[0];
|
||||
});
|
||||
filter.where = where;
|
||||
}
|
||||
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);
|
||||
|
||||
let stmt = new ParameterizedSQL(query);
|
||||
stmt.merge(conn.makeSuffix(myFilter));
|
||||
return conn.executeStmt(stmt);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('activeWithBuyer', {
|
||||
description: 'Returns active workers in itemType',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'filter',
|
||||
type: 'Object',
|
||||
description: 'Filter defining where and paginated data',
|
||||
required: false
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/activeWithBuyer`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.activeWithBuyer = async filter => {
|
||||
const query =
|
||||
`SELECT DISTINCT w.id, w.firstName, w.lastName, u.name, u.nickname
|
||||
FROM worker w
|
||||
JOIN itemType i ON i.workerFk = w.id
|
||||
JOIN account.user u ON u.id = w.id`;
|
||||
|
||||
return Self.activeWorkers(query, filter);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Worker activeWithBuyer', () => {
|
||||
it('should return the buyers in itemType as result', async() => {
|
||||
const filter = {};
|
||||
const result = await models.Item.activeWithBuyer(filter);
|
||||
const firstWorker = result[0];
|
||||
const secondWorker = result[1];
|
||||
|
||||
expect(result.length).toEqual(2);
|
||||
expect(firstWorker.nickname).toEqual('logisticBossNick');
|
||||
expect(secondWorker.nickname).toEqual('buyerNick');
|
||||
});
|
||||
});
|
|
@ -14,6 +14,8 @@ module.exports = Self => {
|
|||
require('../methods/item/getWasteByWorker')(Self);
|
||||
require('../methods/item/getWasteByItem')(Self);
|
||||
require('../methods/item/createIntrastat')(Self);
|
||||
require('../methods/item/active')(Self);
|
||||
require('../methods/item/activeWithBuyer')(Self);
|
||||
|
||||
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
||||
|
||||
|
|
|
@ -41,12 +41,10 @@
|
|||
<vn-autocomplete
|
||||
vn-one
|
||||
disabled="false"
|
||||
ng-model="filter.salesPersonFk"
|
||||
url="Workers/activeWithRole"
|
||||
url="Items/activeWithBuyer"
|
||||
show-field="nickname"
|
||||
search-function="{firstName: $search}"
|
||||
value-field="id"
|
||||
where="{role: {inq: ['logistic', 'buyer']}}"
|
||||
label="Buyer">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
|
|
Loading…
Reference in New Issue