MASTER_hotFix(monitor): fix left join salesFilter #1042

Merged
joan merged 1 commits from hotFix_salesFilter_straight_join into master 2022-09-07 07:04:03 +00:00
2 changed files with 8 additions and 12 deletions

View File

@ -207,7 +207,7 @@ module.exports = Self => {
LEFT JOIN province p ON p.id = a.provinceFk LEFT JOIN province p ON p.id = a.provinceFk
LEFT JOIN warehouse w ON w.id = t.warehouseFk LEFT JOIN warehouse w ON w.id = t.warehouseFk
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN ticketState ts ON ts.ticketFk = t.id STRAIGHT_JOIN ticketState ts ON ts.ticketFk = t.id
LEFT JOIN state st ON st.id = ts.stateFk LEFT JOIN state st ON st.id = ts.stateFk
LEFT JOIN client c ON c.id = t.clientFk LEFT JOIN client c ON c.id = t.clientFk
LEFT JOIN worker wk ON wk.id = c.salesPersonFk LEFT JOIN worker wk ON wk.id = c.salesPersonFk
@ -227,7 +227,7 @@ module.exports = Self => {
// Get client debt balance // Get client debt balance
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt'); stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt');
stmts.push(` stmts.push(`
CREATE TEMPORARY TABLE tmp.clientGetDebt CREATE TEMPORARY TABLE tmp.clientGetDebt
(PRIMARY KEY (clientFk)) (PRIMARY KEY (clientFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT DISTINCT clientFk FROM tmp.filter`); SELECT DISTINCT clientFk FROM tmp.filter`);
@ -238,7 +238,7 @@ module.exports = Self => {
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.tickets'); stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.tickets');
stmt = new ParameterizedSQL(` stmt = new ParameterizedSQL(`
CREATE TEMPORARY TABLE tmp.tickets CREATE TEMPORARY TABLE tmp.tickets
(PRIMARY KEY (id)) (PRIMARY KEY (id))
ENGINE = MEMORY ENGINE = MEMORY
SELECT f.*, r.risk AS debt SELECT f.*, r.risk AS debt
@ -268,10 +268,10 @@ module.exports = Self => {
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems'); stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems');
stmt = new ParameterizedSQL(` stmt = new ParameterizedSQL(`
CREATE TEMPORARY TABLE tmp.sale_getProblems CREATE TEMPORARY TABLE tmp.sale_getProblems
(INDEX (ticketFk)) (INDEX (ticketFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped
FROM tmp.filter f FROM tmp.filter f
LEFT JOIN alertLevel al ON al.id = f.alertLevel LEFT JOIN alertLevel al ON al.id = f.alertLevel
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL) WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
@ -377,7 +377,7 @@ module.exports = Self => {
const ticketsIndex = stmts.push(stmt) - 1; const ticketsIndex = stmts.push(stmt) - 1;
stmts.push( stmts.push(
`DROP TEMPORARY TABLE `DROP TEMPORARY TABLE
tmp.filter, tmp.filter,
tmp.ticket_problems, tmp.ticket_problems,
tmp.sale_getProblems, tmp.sale_getProblems,

View File

@ -147,16 +147,12 @@ describe('SalesMonitor salesFilter()', () => {
const options = {transaction: tx}; const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}}; const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}};
const filter = {}; const filter = {order: 'alertLevel ASC'};
const result = await models.SalesMonitor.salesFilter(ctx, filter, options); const result = await models.SalesMonitor.salesFilter(ctx, filter, options);
const firstRow = result[0]; const firstRow = result[0];
const secondRow = result[1];
const thirdRow = result[2];
expect(result.length).toEqual(12); expect(result.length).toEqual(12);
expect(firstRow.state).toEqual('Entregado'); expect(firstRow.alertLevel).not.toEqual(0);
expect(secondRow.state).toEqual('Entregado');
expect(thirdRow.state).toEqual('Entregado');
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {