update ticket.filter
gitea/salix/2023-ticket_index_advanced_search This commit looks good
Details
gitea/salix/2023-ticket_index_advanced_search This commit looks good
Details
This commit is contained in:
parent
84d6d7cec0
commit
8193b0ffc0
|
@ -63,6 +63,10 @@ module.exports = Self => {
|
|||
arg: 'myTeam',
|
||||
type: 'Boolean',
|
||||
description: `Whether to show only tickets for the current logged user team (For now it shows only the current user tickets)`
|
||||
}, {
|
||||
arg: 'problems',
|
||||
type: 'Boolean',
|
||||
description: `Whether to show only tickets with problems`
|
||||
}, {
|
||||
arg: 'mine',
|
||||
type: 'Boolean',
|
||||
|
@ -239,6 +243,38 @@ module.exports = Self => {
|
|||
FROM tmp.filter f
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
|
||||
LEFT JOIN tmp.ticketTotal tt ON tt.ticketFk = f.id`);
|
||||
|
||||
|
||||
let condition;
|
||||
let hasProblem;
|
||||
let range;
|
||||
let hasWhere;
|
||||
switch (ctx.args.problems) {
|
||||
case true:
|
||||
condition = `or`;
|
||||
hasProblem = true;
|
||||
range = 0;
|
||||
hasWhere = true;
|
||||
break;
|
||||
|
||||
case false:
|
||||
condition = `and`;
|
||||
hasProblem = null;
|
||||
range = null;
|
||||
hasWhere = true;
|
||||
break;
|
||||
}
|
||||
|
||||
let problems = {[condition]: [
|
||||
{'tp.isFreezed': hasProblem},
|
||||
{'tp.risk': hasProblem},
|
||||
{'tp.hasTicketRequest': hasProblem},
|
||||
{'tp.isAvailable': range}
|
||||
]};
|
||||
|
||||
if (hasWhere)
|
||||
stmt.merge(conn.makeWhere(problems));
|
||||
|
||||
stmt.merge(conn.makeOrderBy(filter.order));
|
||||
let ticketsIndex = stmts.push(stmt);
|
||||
|
||||
|
|
|
@ -10,4 +10,31 @@ describe('ticket filter()', () => {
|
|||
|
||||
expect(ticketId).toEqual(24);
|
||||
});
|
||||
|
||||
it('should return the tickets matching the problems on true', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 9}}, args: {problems: true}};
|
||||
|
||||
let filter = {};
|
||||
let result = await app.models.Ticket.filter(ctx, filter);
|
||||
|
||||
expect(result.length).toEqual(4);
|
||||
});
|
||||
|
||||
it('should return the tickets matching the problems on false', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 9}}, args: {problems: false}};
|
||||
|
||||
let filter = {};
|
||||
let result = await app.models.Ticket.filter(ctx, filter);
|
||||
|
||||
expect(result.length).toEqual(20);
|
||||
});
|
||||
|
||||
it('should return the tickets matching the problems on null', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 9}}, args: {problems: null}};
|
||||
|
||||
let filter = {};
|
||||
let result = await app.models.Ticket.filter(ctx, filter);
|
||||
|
||||
expect(result.length).toEqual(24);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -91,12 +91,6 @@
|
|||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-check
|
||||
vn-one
|
||||
label="My team"
|
||||
ng-model="filter.myTeam"
|
||||
triple-state="true">
|
||||
</vn-check>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
label="Warehouse"
|
||||
|
@ -110,6 +104,20 @@
|
|||
url="Provinces">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-check
|
||||
vn-one
|
||||
label="My team"
|
||||
ng-model="filter.myTeam"
|
||||
triple-state="true">
|
||||
</vn-check>
|
||||
<vn-check
|
||||
vn-one
|
||||
label="Problems"
|
||||
ng-model="filter.problems"
|
||||
triple-state="true">
|
||||
</vn-check>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal class="vn-mt-lg">
|
||||
<vn-submit label="Search"></vn-submit>
|
||||
</vn-horizontal>
|
||||
|
|
Loading…
Reference in New Issue