2081 - Fix ticket search by order id
gitea/salix/2081-fix_ticket_search_by_order This commit looks good
Details
gitea/salix/2081-fix_ticket_search_by_order This commit looks good
Details
This commit is contained in:
parent
40f5093106
commit
415316d7d0
|
@ -96,7 +96,8 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.filter = async(ctx, filter) => {
|
||||
let conn = Self.dataSource.connector;
|
||||
const conn = Self.dataSource.connector;
|
||||
const args = ctx.args;
|
||||
|
||||
let worker = await Self.app.models.Worker.findOne({
|
||||
where: {userFk: ctx.req.accessToken.userId},
|
||||
|
@ -107,13 +108,13 @@ module.exports = Self => {
|
|||
|
||||
let teamIds = [];
|
||||
|
||||
if (worker.collegues().length && ctx.args.myTeam) {
|
||||
if (worker.collegues().length && args.myTeam) {
|
||||
worker.collegues().forEach(collegue => {
|
||||
teamIds.push(collegue.collegueFk);
|
||||
});
|
||||
}
|
||||
|
||||
if (ctx.args.mine || (worker.collegues().length === 0 && ctx.args.myTeam)) {
|
||||
if (args.mine || (worker.collegues().length === 0 && args.myTeam)) {
|
||||
worker = await Self.app.models.Worker.findOne({
|
||||
fields: ['id'],
|
||||
where: {userFk: ctx.req.accessToken.userId}
|
||||
|
@ -121,23 +122,14 @@ module.exports = Self => {
|
|||
teamIds = [worker && worker.id];
|
||||
}
|
||||
|
||||
if (ctx.args && (ctx.args.mine || ctx.args.myTeam))
|
||||
ctx.args.teamIds = teamIds;
|
||||
if (ctx.args && (args.mine || args.myTeam))
|
||||
args.teamIds = teamIds;
|
||||
|
||||
if (ctx.args && ctx.args.to) {
|
||||
const dateTo = ctx.args.to;
|
||||
if (ctx.args && args.to) {
|
||||
const dateTo = args.to;
|
||||
dateTo.setHours(23, 59, 0, 0);
|
||||
}
|
||||
|
||||
let orderTickets = [];
|
||||
if (ctx.args && ctx.args.orderFk) {
|
||||
let ticketsToSearch = await Self.app.models.OrderTicket.find({where: {orderFk: ctx.args.orderFk}});
|
||||
ticketsToSearch.forEach(ticket => {
|
||||
orderTickets.push(ticket.ticketFk);
|
||||
});
|
||||
ctx.args.search = orderTickets;
|
||||
}
|
||||
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
|
@ -215,6 +207,14 @@ module.exports = Self => {
|
|||
LEFT JOIN client c ON c.id = t.clientFk
|
||||
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
||||
LEFT JOIN account.user u ON u.id = wk.userFk`);
|
||||
|
||||
if (args.orderFk) {
|
||||
stmt.merge({
|
||||
sql: `JOIN orderTicket ot ON ot.ticketFk = t.id AND ot.orderFk = ?`,
|
||||
params: [args.orderFk]
|
||||
});
|
||||
}
|
||||
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
stmts.push(stmt);
|
||||
|
||||
|
@ -249,7 +249,7 @@ module.exports = Self => {
|
|||
let hasProblem;
|
||||
let range;
|
||||
let hasWhere;
|
||||
switch (ctx.args.problems) {
|
||||
switch (args.problems) {
|
||||
case true:
|
||||
condition = `or`;
|
||||
hasProblem = true;
|
||||
|
|
|
@ -2,39 +2,45 @@ const app = require('vn-loopback/server/server');
|
|||
|
||||
describe('ticket filter()', () => {
|
||||
it('should return the tickets matching the filter', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 9}}, args: {}};
|
||||
|
||||
let filter = {order: 'id DESC'};
|
||||
let result = await app.models.Ticket.filter(ctx, filter);
|
||||
let ticketId = result[0].id;
|
||||
const ctx = {req: {accessToken: {userId: 9}}, args: {}};
|
||||
const filter = {order: 'id DESC'};
|
||||
const result = await app.models.Ticket.filter(ctx, filter);
|
||||
const ticketId = result[0].id;
|
||||
|
||||
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);
|
||||
const ctx = {req: {accessToken: {userId: 9}}, args: {problems: true}};
|
||||
const filter = {};
|
||||
const 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);
|
||||
const ctx = {req: {accessToken: {userId: 9}}, args: {problems: false}};
|
||||
const filter = {};
|
||||
const 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);
|
||||
const ctx = {req: {accessToken: {userId: 9}}, args: {problems: null}};
|
||||
const filter = {};
|
||||
const result = await app.models.Ticket.filter(ctx, filter);
|
||||
|
||||
expect(result.length).toEqual(24);
|
||||
});
|
||||
|
||||
it('should return the tickets matching the orderId 11', async() => {
|
||||
const ctx = {req: {accessToken: {userId: 9}}, args: {orderFk: 11}};
|
||||
const filter = {};
|
||||
const result = await app.models.Ticket.filter(ctx, filter);
|
||||
const firstRow = result[0];
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(firstRow.ticketFk).toEqual(11);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue