#1188 item.index filtering doesnt work for some params
gitea/salix/dev This commit looks good Details

This commit is contained in:
Gerard 2019-03-05 11:34:05 +01:00
parent 80ebf671e8
commit 7f10a509e0
1 changed files with 27 additions and 13 deletions

View File

@ -23,6 +23,11 @@ module.exports = Self => {
type: 'String', type: 'String',
description: `If it's and integer searchs by id, otherwise it searchs by name`, description: `If it's and integer searchs by id, otherwise it searchs by name`,
http: {source: 'query'} http: {source: 'query'}
}, {
arg: 'id',
type: 'Integer',
description: 'Item id',
http: {source: 'query'}
}, { }, {
arg: 'categoryFk', arg: 'categoryFk',
type: 'Integer', type: 'Integer',
@ -71,7 +76,7 @@ module.exports = Self => {
case 'categoryFk': case 'categoryFk':
return {'ic.id': value}; return {'ic.id': value};
case 'typeFk': case 'typeFk':
return {'t.id': value}; return {'i.typeFk': value};
case 'isActive': case 'isActive':
return {'i.isActive': value}; return {'i.isActive': value};
} }
@ -96,10 +101,10 @@ module.exports = Self => {
ic.name AS category, i.density, tc.description AS taxClass, ic.name AS category, i.density, tc.description AS taxClass,
b.grouping, b.packing b.grouping, b.packing
FROM item i FROM item i
JOIN itemType t ON t.id = i.typeFk LEFT JOIN itemType t ON t.id = i.typeFk
LEFT JOIN itemCategory ic ON ic.id = t.categoryFk LEFT JOIN itemCategory ic ON ic.id = t.categoryFk
JOIN worker w ON w.id = t.workerFk LEFT JOIN worker w ON w.id = t.workerFk
JOIN account.user u ON u.id = w.userFk LEFT JOIN account.user u ON u.id = w.userFk
LEFT JOIN intrastat intr ON intr.id = i.intrastatFk LEFT JOIN intrastat intr ON intr.id = i.intrastatFk
LEFT JOIN producer pr ON pr.id = i.producerFk LEFT JOIN producer pr ON pr.id = i.producerFk
LEFT JOIN origin ori ON ori.id = i.originFk LEFT JOIN origin ori ON ori.id = i.originFk
@ -118,17 +123,26 @@ module.exports = Self => {
if (ctx.args.tags) { if (ctx.args.tags) {
let i = 1; let i = 1;
for (let tag of ctx.args.tags) { for (const tag of ctx.args.tags) {
if (tag.value == null) continue; const tAlias = `it${i++}`;
let tAlias = `it${i++}`;
stmt.merge({ if (tag.tagFk) {
sql: `JOIN itemTag ${tAlias} ON ${tAlias}.itemFk = i.id stmt.merge({
AND ${tAlias}.tagFk = ? sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id
AND ${tAlias}.value = ?`, AND ${tAlias}.tagFk = ?
params: [tag.tagFk, tag.value] AND ${tAlias}.value LIKE ?`,
}); params: [tag.tagFk, `%${tag.value}%`],
});
} else {
stmt.merge({
sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id
AND ${tAlias}.value LIKE ?`,
params: [`%${tag.value}%`],
});
}
} }
} }
stmt.merge(conn.makeSuffix(filter)); stmt.merge(conn.makeSuffix(filter));
let itemsIndex = stmts.push(stmt) - 1; let itemsIndex = stmts.push(stmt) - 1;