4846-claim.search-panel #1174

Merged
vicent merged 18 commits from 4846-claim.search-panel into dev 2023-01-10 13:09:23 +00:00
1 changed files with 26 additions and 27 deletions
Showing only changes of commit eb4cb318ed - Show all commits

View File

@ -100,6 +100,26 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
let claimIdsByItemFk = [];
let claimIdsByClaimResponsibleFk = [];
if (args.itemFk) {
query = `SELECT cb.claimFk
FROM claimBeginning cb
LEFT JOIN sale s ON s.id = cb.saleFk
WHERE s.itemFk = ?`;
const claims = await Self.rawSql(query, [args.itemFk], myOptions);
claimIdsByItemFk = claims.map(claim => claim.claimFk);
}
if (args.claimResponsibleFk) {
query = `SELECT cd.claimFk
FROM claimDevelopment cd
WHERE cd.claimResponsibleFk = ?`;
const claims = await Self.rawSql(query, [args.claimResponsibleFk], myOptions);
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
}
const where = buildFilter(args, (param, value) => {
switch (param) {
case 'search':
@ -118,7 +138,9 @@ module.exports = Self => {
case 'priority':
return {[`cl.${param}`]: value};
case 'itemFk':
return {[`s.${param}`]: value};
return {'cl.id': {inq: claimIdsByItemFk}};
vicent marked this conversation as resolved
Review

revisar si llamando a itemFk y claimResponsibleFk construye los dos

revisar si llamando a itemFk y claimResponsibleFk construye los dos
Review

Construye los dos, con un and:
{ and: [ { 'cl.id': [Object] }, { 'cl.id': [Object] } ] }

Construye los dos, con un and: { and: [ { 'cl.id': [Object] }, { 'cl.id': [Object] } ] }
case 'claimResponsibleFk':
return {'cl.id': {inq: claimIdsByClaimResponsibleFk}};
case 'salesPersonFk':
return {'c.salesPersonFk': value};
case 'attenderFk':
@ -144,42 +166,19 @@ module.exports = Self => {
cl.workerFk,
u.name AS workerName,
cs.description,
cl.created,
cs.priority,
cl.claimStateFk,
c.salesPersonFk,
s.itemFk
cl.created
FROM claim cl
LEFT JOIN client c ON c.id = cl.clientFk
LEFT JOIN worker w ON w.id = cl.workerFk
LEFT JOIN account.user u ON u.id = w.userFk
vicent marked this conversation as resolved Outdated

worker no es necesaria, directament en user.

worker no es necesaria, directament en user.
LEFT JOIN claimState cs ON cs.id = cl.claimStateFk
LEFT JOIN claimBeginning cb ON cb.claimFk = cl.id
LEFT JOIN sale s ON s.id = cb.saleFk`
LEFT JOIN claimState cs ON cs.id = cl.claimStateFk`
);
if (args.claimResponsibleFk) {
query = `SELECT cd.claimFk
FROM claimDevelopment cd
WHERE cd.claimResponsibleFk = ?`;
const claimDevelopments = await Self.rawSql(query, [args.claimResponsibleFk], myOptions);
const claimIds = claimDevelopments.map(claimDevelopment => {
return claimDevelopment.claimFk;
});
stmt.merge({
sql: `LEFT JOIN claimDevelopment cd ON cd.claimFk = cl.id
WHERE cl.id IN (?)
GROUP BY cl.id`,
params: [claimIds],
});
}
stmt.merge(conn.makeSuffix(filter));
const itemsIndex = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';');
console.log(sql);
const result = await conn.executeStmt(sql, myOptions);
return itemsIndex === 0 ? result : result[itemsIndex];