From d47429b4a7db95f8d549ac858652288f218dca71 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 17 Jan 2024 10:01:38 +0100 Subject: [PATCH 1/4] refs #6667 sql --- modules/worker/back/methods/worker/search.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 7fe9e0666..2cef3543b 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -41,13 +41,15 @@ module.exports = Self => { } const stmt = new ParameterizedSQL(` - SELECT * - FROM( - SELECT DISTINCT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk - FROM worker w - JOIN account.user u ON u.id = w.id - LEFT JOIN business b ON b.workerFk = w.id - ) w`); + SELECT * + FROM( + SELECT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk + FROM worker w + JOIN account.user u ON u.id = w.id + LEFT JOIN business b ON b.workerFk = w.id + ORDER BY b.id DESC + ) w + GROUP BY w.id`); stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); From d1a3c67d2ea296971c4f7390be827cfe554ff2f9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 17 Jan 2024 14:07:04 +0100 Subject: [PATCH 2/4] refs #6667 fix limit --- modules/worker/back/methods/worker/search.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 2cef3543b..e423f660d 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -42,14 +42,15 @@ module.exports = Self => { const stmt = new ParameterizedSQL(` SELECT * - FROM( - SELECT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk - FROM worker w - JOIN account.user u ON u.id = w.id - LEFT JOIN business b ON b.workerFk = w.id - ORDER BY b.id DESC - ) w - GROUP BY w.id`); + FROM( + SELECT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk + FROM worker w + JOIN account.user u ON u.id = w.id + LEFT JOIN business b ON b.workerFk = w.id + ORDER BY b.id DESC + LIMIT 10000000000000000000 + ) w + GROUP BY w.id`); stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); From ccdef0458a566849a5381e6357a39843cfe508e3 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 17 Jan 2024 14:39:11 +0100 Subject: [PATCH 3/4] refs #6667 fix groupBy --- modules/worker/back/methods/worker/search.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index e423f660d..59348a9ce 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -49,10 +49,14 @@ module.exports = Self => { LEFT JOIN business b ON b.workerFk = w.id ORDER BY b.id DESC LIMIT 10000000000000000000 - ) w - GROUP BY w.id`); + ) w`); + + stmt.merge(conn.makeSuffix(filter.fields)); + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge(conn.makeGroupBy('w.id')); + stmt.merge(conn.makeOrderBy(filter.order)); + stmt.merge(conn.makeLimit(filter.limit)); - stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); }; From 0f104e54103580f8b879bbfef21227496533c397 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 19 Jan 2024 10:11:33 +0100 Subject: [PATCH 4/4] refs #6667 view workerDepartment --- modules/worker/back/methods/worker/search.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 59348a9ce..07bdfe240 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -43,19 +43,13 @@ module.exports = Self => { const stmt = new ParameterizedSQL(` SELECT * FROM( - SELECT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk + SELECT w.id, w.code, u.name, u.nickname, u.active, wd.departmentFk FROM worker w JOIN account.user u ON u.id = w.id - LEFT JOIN business b ON b.workerFk = w.id - ORDER BY b.id DESC - LIMIT 10000000000000000000 + LEFT JOIN workerDepartment wd ON wd.workerFk = w.id ) w`); - stmt.merge(conn.makeSuffix(filter.fields)); - stmt.merge(conn.makeWhere(filter.where)); - stmt.merge(conn.makeGroupBy('w.id')); - stmt.merge(conn.makeOrderBy(filter.order)); - stmt.merge(conn.makeLimit(filter.limit)); + stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); };