This commit is contained in:
parent
5797398cf2
commit
6f4a12e50f
|
@ -63,4 +63,27 @@ describe('Client transactions', () => {
|
||||||
throw e;
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,6 +28,16 @@ module.exports = Self => {
|
||||||
arg: 'amount',
|
arg: 'amount',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
http: {source: 'query'}
|
http: {source: 'query'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'from',
|
||||||
|
type: 'date',
|
||||||
|
http: {source: 'query'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'to',
|
||||||
|
type: 'date',
|
||||||
|
http: {source: 'query'}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -47,6 +57,11 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
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) => {
|
const where = buildFilter(args, (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'orderFk':
|
case 'orderFk':
|
||||||
|
@ -55,6 +70,11 @@ module.exports = Self => {
|
||||||
return {'t.clientFk': value};
|
return {'t.clientFk': value};
|
||||||
case 'amount':
|
case 'amount':
|
||||||
return {'t.amount': (value * 100)};
|
return {'t.amount': (value * 100)};
|
||||||
|
case 'from':
|
||||||
|
return {'t.created': {gte: value}};
|
||||||
|
|
||||||
|
case 'to':
|
||||||
|
return {'t.created': {lte: value}};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue