ref #5417 date filters added
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Jorge Penadés 2023-09-29 14:42:47 +02:00
parent 5797398cf2
commit 6f4a12e50f
2 changed files with 43 additions and 0 deletions

View File

@ -63,4 +63,27 @@ describe('Client transactions', () => {
throw e;
}
});
it('should call transactions() method filtering by date', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {args: {from: '2000/12/31'}};
const filter = {};
const withResults = await models.Client.transactions(ctx, filter, options);
expect(withResults.length).toEqual(6);
ctx.args.from = '2099/12/31';
const noResults = await models.Client.transactions(ctx, filter, options);
expect(noResults.length).toEqual(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -28,6 +28,16 @@ module.exports = Self => {
arg: 'amount',
type: 'number',
http: {source: 'query'}
},
{
arg: 'from',
type: 'date',
http: {source: 'query'}
},
{
arg: 'to',
type: 'date',
http: {source: 'query'}
}
],
returns: {
@ -47,6 +57,11 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
if (ctx.args && args.to) {
const dateTo = args.to;
dateTo.setHours(23, 59, 0, 0);
}
const where = buildFilter(args, (param, value) => {
switch (param) {
case 'orderFk':
@ -55,6 +70,11 @@ module.exports = Self => {
return {'t.clientFk': value};
case 'amount':
return {'t.amount': (value * 100)};
case 'from':
return {'t.created': {gte: value}};
case 'to':
return {'t.created': {lte: value}};
}
});