parent
ca48ad9777
commit
b28a8a34dc
|
@ -2,6 +2,7 @@
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
|
const DEFAULT_INTERVAL_DAYS = 3;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('filter', {
|
Self.remoteMethodCtx('filter', {
|
||||||
|
@ -95,6 +96,11 @@ module.exports = Self => {
|
||||||
arg: 'to',
|
arg: 'to',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: `The to date filter`
|
description: `The to date filter`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'days',
|
||||||
|
type: 'number',
|
||||||
|
description: `N days interval`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -183,15 +189,26 @@ module.exports = Self => {
|
||||||
t.landed,
|
t.landed,
|
||||||
t.ref AS travelRef,
|
t.ref AS travelRef,
|
||||||
t.warehouseInFk,
|
t.warehouseInFk,
|
||||||
w.name warehouseInName
|
w.name warehouseInName,
|
||||||
|
util.VN_CURDATE()
|
||||||
FROM vn.entry e
|
FROM vn.entry e
|
||||||
JOIN vn.supplier s ON s.id = e.supplierFk
|
JOIN vn.supplier s ON s.id = e.supplierFk
|
||||||
JOIN vn.travel t ON t.id = e.travelFk
|
JOIN vn.travel t ON t.id = e.travelFk
|
||||||
JOIN vn.warehouse w ON w.id = t.warehouseInFk
|
JOIN vn.warehouse w ON w.id = t.warehouseInFk
|
||||||
JOIN vn.company co ON co.id = e.companyFk
|
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) {
|
||||||
|
stmt.merge({
|
||||||
|
sql: `
|
||||||
|
AND t.shipped < util.VN_CURDATE() + INTERVAL ? + 1 DAY
|
||||||
|
AND t.shipped >= util.VN_CURDATE()
|
||||||
|
`,
|
||||||
|
params: Array(1).fill(ctx.args.days ?? DEFAULT_INTERVAL_DAYS)
|
||||||
|
});
|
||||||
|
}
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
const itemsIndex = stmts.push(stmt) - 1;
|
const itemsIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(9);
|
expect(result.length).toEqual(14);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -61,7 +61,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(6);
|
expect(result.length).toEqual(8);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -84,7 +84,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(6);
|
expect(result.length).toEqual(8);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -107,7 +107,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(6);
|
expect(result.length).toEqual(11);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -131,7 +131,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(8);
|
expect(result.length).toEqual(13);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue