Merge pull request '2384 - Searchbar filters fixed' (#349) from 2384-client_consumption into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #349
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Joan Sanchez 2020-08-12 10:06:55 +00:00
commit de1a70aee7
2 changed files with 32 additions and 8 deletions

View File

@ -17,20 +17,20 @@ 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`
}, { }, {
arg: 'itemFk', arg: 'itemId',
type: 'Integer', type: 'Number',
description: 'Item id' description: 'Item id'
}, { }, {
arg: 'categoryFk', arg: 'categoryId',
type: 'Integer', type: 'Number',
description: 'Category id' description: 'Category id'
}, { }, {
arg: 'typeFk', arg: 'typeId',
type: 'Integer', type: 'Number',
description: 'Item type id', description: 'Item type id',
}, { }, {
arg: 'buyerFk', arg: 'buyerId',
type: 'Integer', type: 'Number',
description: 'Buyer id' description: 'Buyer id'
}, { }, {
arg: 'from', arg: 'from',
@ -75,6 +75,10 @@ module.exports = Self => {
return {'it.id': value}; return {'it.id': value};
case 'buyerId': case 'buyerId':
return {'it.workerFk': value}; return {'it.workerFk': value};
case 'from':
return {'t.shipped': {gte: value}};
case 'to':
return {'t.shipped': {lte: value}};
} }
}); });
filter = mergeFilters(filter, {where}); filter = mergeFilters(filter, {where});

View File

@ -37,4 +37,24 @@ describe('client consumption() filter', () => {
expect(secondRow.quantity).toEqual(15); expect(secondRow.quantity).toEqual(15);
expect(thirdRow.quantity).toEqual(20); expect(thirdRow.quantity).toEqual(20);
}); });
it('should return a list of tickets from the item id 4', async() => {
const ctx = {req: {accessToken: {userId: 9}},
args: {
itemId: 4
}
};
const filter = {
where: {
clientFk: 101
},
order: 'itemTypeFk, itemName, itemSize'
};
const result = await app.models.Client.consumption(ctx, filter);
const expectedItemId = 4;
const firstRow = result[0];
expect(firstRow.itemFk).toEqual(expectedItemId);
});
}); });