From c81ca94d2e5c8d7e1a5cb94e2d2da1c0f23dcdce Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 11 Dec 2023 14:44:33 +0100 Subject: [PATCH 1/8] refs #6220 add filter address --- modules/client/back/methods/client/filter.js | 56 +++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index 47d5f6d2f..782d355ca 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -129,25 +129,43 @@ module.exports = Self => { const stmts = []; const stmt = new ParameterizedSQL( `SELECT - DISTINCT c.id, - c.name, - c.fi, - c.socialName, - c.phone, - c.mobile, - c.city, - c.postcode, - c.email, - c.isActive, - c.isFreezed, - p.id AS provinceFk, - p.name AS province, - u.id AS salesPersonFk, - u.name AS salesPerson - FROM client c - LEFT JOIN account.user u ON u.id = c.salesPersonFk - LEFT JOIN province p ON p.id = c.provinceFk - JOIN vn.address a ON a.clientFk = c.id + DISTINCT c.id, + c.name, + c.fi, + c.socialName, + c.phone, + c.mobile, + c.city, + c.postcode, + c.email, + c.isActive, + c.isFreezed, + p.id AS provinceFk, + p.name AS province, + u.id AS salesPersonFk, + u.name AS salesPerson, + a.street, + a.city AS addressCity, + a.provinceFk AS addressProvinceFk, + a.postalCode AS addressPostalCode, + a.phone AS addressPhone, + a.mobile AS addressMobile, + a.nickname, + a.isDefaultAddress, + a.agencyModeFk AS addressAgencyModeFk, + a.isActive AS addressIsActive, + a.longitude AS addressLongitude, + a.latitude AS addressLatitude, + a.isEqualizated, + a.customsAgentFk AS addressCustomsAgentFk, + a.incotermsFk AS addressIncotermsFk, + a.isLogifloraAllowed, + a.editorFk AS addressEditorFk + FROM client c + LEFT JOIN account.user u ON u.id = c.salesPersonFk + LEFT JOIN province p ON p.id = c.provinceFk + JOIN vn.address a ON a.clientFk = c.id; + ` ); From 7e6f311a431502c72abd7116a76518638bcc0160 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 11 Dec 2023 14:51:11 +0100 Subject: [PATCH 2/8] refs #6220 address filter --- modules/client/back/methods/client/filter.js | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index 782d355ca..d88f15c3f 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -140,27 +140,27 @@ module.exports = Self => { c.email, c.isActive, c.isFreezed, - p.id AS provinceFk, - p.name AS province, - u.id AS salesPersonFk, - u.name AS salesPerson, + p.id, + p.name, + u.id, + u.name, a.street, - a.city AS addressCity, - a.provinceFk AS addressProvinceFk, - a.postalCode AS addressPostalCode, - a.phone AS addressPhone, - a.mobile AS addressMobile, + a.city, + a.provinceFk, + a.postalCode, + a.phone, + a.mobile, a.nickname, a.isDefaultAddress, - a.agencyModeFk AS addressAgencyModeFk, - a.isActive AS addressIsActive, - a.longitude AS addressLongitude, - a.latitude AS addressLatitude, + a.agencyModeFk, + a.isActive, + a.longitude, + a.latitude, a.isEqualizated, - a.customsAgentFk AS addressCustomsAgentFk, - a.incotermsFk AS addressIncotermsFk, + a.customsAgentFk, + a.incotermsFk, a.isLogifloraAllowed, - a.editorFk AS addressEditorFk + a.editorFk FROM client c LEFT JOIN account.user u ON u.id = c.salesPersonFk LEFT JOIN province p ON p.id = c.provinceFk From 6cefc982e46261dd680e7e1d5797a2d2ffd1daa9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 12 Dec 2023 13:14:41 +0100 Subject: [PATCH 3/8] refs #6220 add filter address --- modules/client/back/methods/client/filter.js | 81 ++++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index d88f15c3f..43310c86b 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -107,17 +107,29 @@ module.exports = Self => { return {or: [ {'c.phone': {like: `%${value}%`}}, {'c.mobile': {like: `%${value}%`}}, + {'a.phone': {like: `%${value}%`}}, ]}; case 'zoneFk': - param = 'a.postalCode'; - return {[param]: {inq: postalCode}}; + return {'a.postalCode': {inq: postalCode}}; + case 'city': + return {or: [ + {'c.city': {like: `%${value}`}}, + {'a.city': {like: `%${value}`}} + ]}; + case 'postcode': + return {or: [ + {'c.postcode': {like: `%${value}`}}, + {'a.postalCode': {like: `%${value}`}} + ]}; + case 'provinceFk': + return {or: [ + {'p.name': {like: `%${value}`}}, + {'a.provinceFk': {like: `%${value}`}} + ]}; case 'name': case 'salesPersonFk': case 'fi': case 'socialName': - case 'city': - case 'postcode': - case 'provinceFk': case 'email': param = `c.${param}`; return {[param]: {like: `%${value}%`}}; @@ -129,47 +141,32 @@ module.exports = Self => { const stmts = []; const stmt = new ParameterizedSQL( `SELECT - DISTINCT c.id, - c.name, - c.fi, - c.socialName, - c.phone, - c.mobile, - c.city, - c.postcode, - c.email, - c.isActive, - c.isFreezed, - p.id, - p.name, - u.id, - u.name, - a.street, - a.city, - a.provinceFk, - a.postalCode, - a.phone, - a.mobile, - a.nickname, - a.isDefaultAddress, - a.agencyModeFk, - a.isActive, - a.longitude, - a.latitude, - a.isEqualizated, - a.customsAgentFk, - a.incotermsFk, - a.isLogifloraAllowed, - a.editorFk - FROM client c - LEFT JOIN account.user u ON u.id = c.salesPersonFk - LEFT JOIN province p ON p.id = c.provinceFk - JOIN vn.address a ON a.clientFk = c.id; - + DISTINCT c.id, + c.name, + c.fi, + c.socialName, + CONCAT(c.phone, ',',GROUP_CONCAT(DISTINCT a.phone)) phone, + c.mobile, + CONCAT(c.city, ',',GROUP_CONCAT(DISTINCT a.city)) city, + c.postcode, + a.postalCode, + c.email, + c.isActive, + c.isFreezed, + p.id AS provinceFk2, + a.provinceFk, + p.name AS province, + u.id AS salesPersonFk, + u.name AS salesPerson + FROM client c + LEFT JOIN account.user u ON u.id = c.salesPersonFk + LEFT JOIN province p ON p.id = c.provinceFk + JOIN address a ON a.clientFk = c.id ` ); stmt.merge(conn.makeWhere(filter.where)); + stmt.merge('GROUP BY c.id'); stmt.merge(conn.makePagination(filter)); const clientsIndex = stmts.push(stmt) - 1; From 78aa25d74fe7b34c58d9dc0224db3b47312a73d0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 12 Dec 2023 13:21:08 +0100 Subject: [PATCH 4/8] refs #6220 fix testback --- modules/client/back/methods/client/specs/filter.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/back/methods/client/specs/filter.spec.js b/modules/client/back/methods/client/specs/filter.spec.js index 679585050..4a61f8aaf 100644 --- a/modules/client/back/methods/client/specs/filter.spec.js +++ b/modules/client/back/methods/client/specs/filter.spec.js @@ -146,7 +146,7 @@ describe('client filter()', () => { const randomResultClient = result[randomIndex]; expect(result.length).toBeGreaterThanOrEqual(20); - expect(randomResultClient.city.toLowerCase()).toEqual('gotham'); + expect(randomResultClient.city.toLowerCase()).toEqual('gotham,gotham'); await tx.rollback(); } catch (e) { From 40499e44cf8d38dbaadb8501c8829d23ec5f7008 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Dec 2023 15:05:41 +0100 Subject: [PATCH 5/8] refs #6220 remove concat --- modules/client/back/methods/client/filter.js | 10 ++++++---- .../client/back/methods/client/specs/filter.spec.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index 43310c86b..e703ce53d 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -145,16 +145,18 @@ module.exports = Self => { c.name, c.fi, c.socialName, - CONCAT(c.phone, ',',GROUP_CONCAT(DISTINCT a.phone)) phone, + c.phone, + a.phone, c.mobile, - CONCAT(c.city, ',',GROUP_CONCAT(DISTINCT a.city)) city, + c.city, + a.city, c.postcode, a.postalCode, c.email, c.isActive, c.isFreezed, - p.id AS provinceFk2, - a.provinceFk, + p.id AS provinceClientFk, + a.provinceFk AS provinceAddressFk, p.name AS province, u.id AS salesPersonFk, u.name AS salesPerson diff --git a/modules/client/back/methods/client/specs/filter.spec.js b/modules/client/back/methods/client/specs/filter.spec.js index 4a61f8aaf..679585050 100644 --- a/modules/client/back/methods/client/specs/filter.spec.js +++ b/modules/client/back/methods/client/specs/filter.spec.js @@ -146,7 +146,7 @@ describe('client filter()', () => { const randomResultClient = result[randomIndex]; expect(result.length).toBeGreaterThanOrEqual(20); - expect(randomResultClient.city.toLowerCase()).toEqual('gotham,gotham'); + expect(randomResultClient.city.toLowerCase()).toEqual('gotham'); await tx.rollback(); } catch (e) { From bbb9f58a9edaa16b442cedbf7bb3226a18651b1d Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 14 Dec 2023 14:37:14 +0100 Subject: [PATCH 6/8] refs #6220 fix(client_filter): fix where --- modules/client/back/methods/client/filter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index e703ce53d..f805c4be9 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -113,18 +113,18 @@ module.exports = Self => { return {'a.postalCode': {inq: postalCode}}; case 'city': return {or: [ - {'c.city': {like: `%${value}`}}, - {'a.city': {like: `%${value}`}} + {'c.city': {like: `%${value}%`}}, + {'a.city': {like: `%${value}%`}} ]}; case 'postcode': return {or: [ - {'c.postcode': {like: `%${value}`}}, - {'a.postalCode': {like: `%${value}`}} + {'c.postcode': value}, + {'a.postalCode': value} ]}; case 'provinceFk': return {or: [ - {'p.name': {like: `%${value}`}}, - {'a.provinceFk': {like: `%${value}`}} + {'p.id': value}, + {'a.provinceFk': value} ]}; case 'name': case 'salesPersonFk': From d60f2a7f88f44906f300e9c5c060ed4b5ec82f1e Mon Sep 17 00:00:00 2001 From: davidd Date: Tue, 19 Dec 2023 09:43:09 +0100 Subject: [PATCH 7/8] fix: refs #6398 Changed alias of views --- db/changes/235201/02-views.sql | 4 ++-- modules/ticket/back/methods/ticket/state.js | 4 ++-- modules/ticket/back/models/ticket-state.json | 8 ++++---- modules/ticket/back/models/ticket-tracking.json | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/db/changes/235201/02-views.sql b/db/changes/235201/02-views.sql index a0f41594d..af190f596 100644 --- a/db/changes/235201/02-views.sql +++ b/db/changes/235201/02-views.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` VIEW `vn`.`ticketState` AS SELECT `tt`.`created` AS `updated`, `tt`.`stateFk` AS `stateFk`, - `tt`.`userFk` AS `userFk`, + `tt`.`userFk` AS `workerFk`, `tls`.`ticketFk` AS `ticketFk`, `s`.`id` AS `state`, `s`.`order` AS `productionOrder`, @@ -40,7 +40,7 @@ SELECT `ts`.`state` AS `state`, `ts`.`productionOrder` AS `productionOrder`, `ts`.`alertLevel` AS `alertLevel`, - `ts`.`userFk` AS `userFk`, + `ts`.`userFk` AS `worker`, `ts`.`code` AS `code`, `ts`.`updated` AS `updated`, `ts`.`isPicked` AS `isPicked` diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index adac2e42f..01bfbba20 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -51,12 +51,12 @@ module.exports = Self => { params.stateFk = state.id; } - if (!params.userFk) { + if (!params.workerFk) { const worker = await models.Worker.findOne({ where: {id: userId} }, myOptions); - params.userFk = worker.id; + params.workerFk = worker.id; } const ticketState = await models.TicketState.findById(params.ticketFk, { diff --git a/modules/ticket/back/models/ticket-state.json b/modules/ticket/back/models/ticket-state.json index 3ee50fac0..3dd322939 100644 --- a/modules/ticket/back/models/ticket-state.json +++ b/modules/ticket/back/models/ticket-state.json @@ -34,9 +34,9 @@ "foreignKey": "stateFk" }, "user": { - "type": "belongsTo", - "model": "VnUser", - "foreignKey": "userFk" - } + "type": "belongsTo", + "model": "VnUser", + "foreignKey": "workerFk" + } } } diff --git a/modules/ticket/back/models/ticket-tracking.json b/modules/ticket/back/models/ticket-tracking.json index 8b0617145..4b5a4d473 100644 --- a/modules/ticket/back/models/ticket-tracking.json +++ b/modules/ticket/back/models/ticket-tracking.json @@ -37,9 +37,9 @@ "foreignKey": "stateFk" }, "user": { - "type": "belongsTo", - "model": "VnUser", - "foreignKey": "userFk" - } + "type": "belongsTo", + "model": "VnUser", + "foreignKey": "userFk" + } } } From 17e177b7888adf882683876d75f20d6d79b64799 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 19 Dec 2023 10:12:03 +0100 Subject: [PATCH 8/8] fix: refs #6398 Fix tests back --- modules/ticket/back/methods/ticket/state.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index 01bfbba20..adac2e42f 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -51,12 +51,12 @@ module.exports = Self => { params.stateFk = state.id; } - if (!params.workerFk) { + if (!params.userFk) { const worker = await models.Worker.findOne({ where: {id: userId} }, myOptions); - params.workerFk = worker.id; + params.userFk = worker.id; } const ticketState = await models.TicketState.findById(params.ticketFk, {