#7884 added new filter field #2981

Merged
jon merged 15 commits from 7884-AddLabelerField into dev 2024-10-02 05:04:18 +00:00
2 changed files with 51 additions and 12 deletions

View File

@ -106,10 +106,15 @@ module.exports = Self => {
description: `The to shipped date filter`
},
{
arg: 'days',
arg: 'daysOnward',
type: 'number',
description: `N days interval`
},
{
arg: 'daysAgo',
type: 'number',
description: `N days ago interval`
},
{
arg: 'invoiceAmount',
type: 'number',
@ -216,16 +221,29 @@ module.exports = Self => {
JOIN vn.currency cu ON cu.id = e.currencyFk`
);
if (ctx.args.days) {
stmt.merge({
sql: `
AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY
AND t.shipped >= util.VN_CURDATE()
`,
params: [ctx.args.days]
});
stmt.merge(conn.makeWhere(filter.where));
jon marked this conversation as resolved Outdated
Outdated
Review

Revisar si estan los dos a la vez

Revisar si estan los dos a la vez
const {daysAgo, daysOnward} = ctx.args;
Outdated
Review

Jo li diria a chatgpt si teu pot simplificar

Jo li diria a chatgpt si teu pot simplificar
if (daysOnward || daysAgo) {
const params = [];
let today = 'util.VN_CURDATE()';
let from = today;
let to = today;
if (daysAgo) {
from += ' - INTERVAL ? DAY';
params.push(daysAgo);
}
if (daysOnward) {
to += ' + INTERVAL ? DAY';
params.push(daysOnward);
}
const whereDays = (filter.where ? 'AND' : 'WHERE') + ` t.shipped BETWEEN ${from} AND ${to}`;
stmt.merge({sql: whereDays, params});
}
stmt.merge(conn.makeSuffix(filter));
stmt.merge(conn.makePagination(filter));
const itemsIndex = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';');

View File

@ -49,13 +49,13 @@ describe('Entry filter()', () => {
});
describe('should return the entry matching the supplier', () => {
it('when userId is supplier ', async() => {
it('when userId is supplier and searching days onward', async() => {
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};
try {
const ctx = {
args: {days: 6},
args: {daysOnward: 6},
req: {accessToken: {userId: 1102}}
};
@ -70,6 +70,27 @@ describe('Entry filter()', () => {
}
});
it('when userId is supplier and searching days ago', async() => {
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};
try {
const ctx = {
args: {daysAgo: 31},
req: {accessToken: {userId: 1102}}
};
const result = await models.Entry.filter(ctx, options);
expect(result.length).toEqual(6);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('when userId is supplier fetching other supplier', async() => {
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};