diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 77e5f2e67..2e2b8e467 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -2,7 +2,6 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; -const DEFAULT_INTERVAL_DAYS = 3; module.exports = Self => { Self.remoteMethodCtx('filter', { @@ -195,18 +194,16 @@ module.exports = Self => { JOIN vn.travel t ON t.id = e.travelFk JOIN vn.warehouse w ON w.id = t.warehouseInFk JOIN vn.company co ON co.id = e.companyFk - JOIN vn.currency cu ON cu.id = e.currencyFk - ` + JOIN vn.currency cu ON cu.id = e.currencyFk` ); - if (supplier) { - const days = ctx.args.days ?? DEFAULT_INTERVAL_DAYS; + if (supplier && ctx.args.days) { stmt.merge({ sql: ` AND t.shipped < util.VN_CURDATE() + INTERVAL ? + 1 DAY AND t.shipped >= util.VN_CURDATE() `, - params: [days] + params: [ctx.args.days] }); } stmt.merge(conn.makeSuffix(filter)); diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index d08400184..c7156062a 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -39,7 +39,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(14); + expect(result.length).toEqual(11); await tx.rollback(); } catch (e) { @@ -55,13 +55,13 @@ describe('Entry filter()', () => { try { const ctx = { - args: {}, + args: {days: 6}, req: {accessToken: {userId: 1102}} }; const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(8); + expect(result.length).toEqual(2); await tx.rollback(); } catch (e) { @@ -107,7 +107,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(11); + expect(result.length).toEqual(8); await tx.rollback(); } catch (e) { @@ -131,7 +131,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(13); + expect(result.length).toEqual(10); await tx.rollback(); } catch (e) {