4846-claim.search-panel #1174
|
@ -93,33 +93,34 @@ module.exports = Self => {
|
|||
|
||||
Self.filter = async(ctx, filter, options) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
const args = ctx.args;
|
||||
const myOptions = {};
|
||||
let to;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const where = buildFilter(ctx.args, (param, value) => {
|
||||
const where = buildFilter(args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
? {'cl.id': value}
|
||||
: {
|
||||
or: [
|
||||
{'cl.clientName': {like: `%${value}%`}}
|
||||
{'c.name': {like: `%${value}%`}}
|
||||
]
|
||||
};
|
||||
case 'clientName':
|
||||
return {'cl.clientName': {like: `%${value}%`}};
|
||||
return {'c.name': {like: `%${value}%`}};
|
||||
case 'clientFk':
|
||||
case 'id':
|
||||
case 'claimStateFk':
|
||||
case 'itemFk':
|
||||
case 'claimResponsibleFk':
|
||||
case 'priority':
|
||||
return {[`cl.${param}`]: value};
|
||||
case 'itemFk':
|
||||
return {[`s.${param}`]: value};
|
||||
case 'salesPersonFk':
|
||||
return {'cl.salesPersonFk': value};
|
||||
return {'c.salesPersonFk': value};
|
||||
case 'attenderFk':
|
||||
return {'cl.workerFk': value};
|
||||
case 'created':
|
||||
|
@ -131,14 +132,12 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
filter = mergeFilters(ctx.args.filter, {where});
|
||||
filter = mergeFilters(args.filter, {where});
|
||||
vicent marked this conversation as resolved
|
||||
|
||||
const stmts = [];
|
||||
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT *
|
||||
FROM (
|
||||
SELECT DISTINCT
|
||||
`SELECT
|
||||
cl.id,
|
||||
vicent marked this conversation as resolved
jgallego
commented
revisar si llamando a itemFk y claimResponsibleFk construye los dos revisar si llamando a itemFk y claimResponsibleFk construye los dos
vicent
commented
Construye los dos, con un and: Construye los dos, con un and:
{ and: [ { 'cl.id': [Object] }, { 'cl.id': [Object] } ] }
|
||||
cl.clientFk,
|
||||
c.name AS clientName,
|
||||
|
@ -149,18 +148,34 @@ module.exports = Self => {
|
|||
cs.priority,
|
||||
cl.claimStateFk,
|
||||
c.salesPersonFk,
|
||||
s.itemFk,
|
||||
cd.claimResponsibleFk
|
||||
s.itemFk
|
||||
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
|
||||
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`
|
||||
LEFT JOIN sale s ON s.id = cb.saleFk`
|
||||
);
|
||||
|
||||
if (args.claimResponsibleFk) {
|
||||
query = `SELECT cd.claimFk
|
||||
FROM claimDevelopment cd
|
||||
vicent marked this conversation as resolved
jgallego
commented
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 (?)
|
||||
vicent marked this conversation as resolved
Outdated
jgallego
commented
worker no es necesaria, directament en user. worker no es necesaria, directament en user.
|
||||
GROUP BY cl.id`,
|
||||
params: [claimIds],
|
||||
});
|
||||
}
|
||||
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
const itemsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
revisar si falla, parece que deberia ser c.clientName
Sí que funciona