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 45 additions and 30 deletions
Showing only changes of commit 9bcef08397 - Show all commits

View File

@ -93,33 +93,34 @@ module.exports = Self => {
Self.filter = async(ctx, filter, options) => { Self.filter = async(ctx, filter, options) => {
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const args = ctx.args;
const myOptions = {}; const myOptions = {};
let to; let to;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const where = buildFilter(ctx.args, (param, value) => { const where = buildFilter(args, (param, value) => {
switch (param) { switch (param) {
case 'search': case 'search':
return /^\d+$/.test(value) return /^\d+$/.test(value)
? {'cl.id': value} ? {'cl.id': value}
: { : {
or: [ or: [
{'cl.clientName': {like: `%${value}%`}} {'c.name': {like: `%${value}%`}}
] ]
}; };
case 'clientName': case 'clientName':
return {'cl.clientName': {like: `%${value}%`}}; return {'c.name': {like: `%${value}%`}};
case 'clientFk': case 'clientFk':
case 'id': case 'id':
case 'claimStateFk': case 'claimStateFk':
case 'itemFk':
case 'claimResponsibleFk':
case 'priority': case 'priority':
return {[`cl.${param}`]: value}; return {[`cl.${param}`]: value};
case 'itemFk':
return {[`s.${param}`]: value};
case 'salesPersonFk': case 'salesPersonFk':
return {'cl.salesPersonFk': value}; return {'c.salesPersonFk': value};
case 'attenderFk': case 'attenderFk':
return {'cl.workerFk': value}; return {'cl.workerFk': value};
case 'created': case 'created':
@ -131,36 +132,50 @@ module.exports = Self => {
} }
}); });
filter = mergeFilters(ctx.args.filter, {where}); filter = mergeFilters(args.filter, {where});
vicent marked this conversation as resolved
Review

revisar si falla, parece que deberia ser c.clientName

revisar si falla, parece que deberia ser c.clientName
Review

Sí que funciona

Sí que funciona
const stmts = []; const stmts = [];
const stmt = new ParameterizedSQL( const stmt = new ParameterizedSQL(
`SELECT * `SELECT
FROM ( cl.id,
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] } ] }
SELECT DISTINCT cl.clientFk,
cl.id, c.name AS clientName,
cl.clientFk, cl.workerFk,
c.name AS clientName, u.name AS workerName,
cl.workerFk, cs.description,
u.name AS workerName, cl.created,
cs.description, cs.priority,
cl.created, cl.claimStateFk,
cs.priority, c.salesPersonFk,
cl.claimStateFk, s.itemFk
c.salesPersonFk, FROM claim cl
s.itemFk, LEFT JOIN client c ON c.id = cl.clientFk
cd.claimResponsibleFk LEFT JOIN worker w ON w.id = cl.workerFk
FROM claim cl LEFT JOIN account.user u ON u.id = w.userFk
LEFT JOIN client c ON c.id = cl.clientFk LEFT JOIN claimState cs ON cs.id = cl.claimStateFk
LEFT JOIN worker w ON w.id = cl.workerFk LEFT JOIN claimBeginning cb ON cb.claimFk = cl.id
LEFT JOIN account.user u ON u.id = w.userFk LEFT JOIN sale s ON s.id = cb.saleFk`
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 claimDevelopment cd ON cd.claimFk = cl.id ) cl`
); );
if (args.claimResponsibleFk) {
query = `SELECT cd.claimFk
FROM claimDevelopment cd
vicent marked this conversation as resolved
Review

usar loopback

usar loopback
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)); stmt.merge(conn.makeSuffix(filter));
const itemsIndex = stmts.push(stmt) - 1; const itemsIndex = stmts.push(stmt) - 1;