Merge pull request '#7884 added new filter field' (!2981) from 7884-AddLabelerField into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2981 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
2fbf8478c0
|
@ -106,10 +106,15 @@ module.exports = Self => {
|
||||||
description: `The to shipped date filter`
|
description: `The to shipped date filter`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'days',
|
arg: 'daysOnward',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: `N days interval`
|
description: `N days interval`
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'daysAgo',
|
||||||
|
type: 'number',
|
||||||
|
description: `N days ago interval`
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'invoiceAmount',
|
arg: 'invoiceAmount',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -216,16 +221,29 @@ module.exports = Self => {
|
||||||
JOIN vn.currency cu ON cu.id = e.currencyFk`
|
JOIN vn.currency cu ON cu.id = e.currencyFk`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ctx.args.days) {
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
stmt.merge({
|
|
||||||
sql: `
|
const {daysAgo, daysOnward} = ctx.args;
|
||||||
AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY
|
if (daysOnward || daysAgo) {
|
||||||
AND t.shipped >= util.VN_CURDATE()
|
const params = [];
|
||||||
`,
|
let today = 'util.VN_CURDATE()';
|
||||||
params: [ctx.args.days]
|
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 itemsIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
|
|
@ -49,13 +49,13 @@ describe('Entry filter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should return the entry matching the supplier', () => {
|
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 tx = await models.Entry.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
args: {days: 6},
|
args: {daysOnward: 6},
|
||||||
req: {accessToken: {userId: 1102}}
|
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() => {
|
it('when userId is supplier fetching other supplier', async() => {
|
||||||
const tx = await models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
Loading…
Reference in New Issue