From afb01ed021d61a00b9c36b05e212a18e08ed8c2e Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 23 Dec 2024 11:55:48 +0100 Subject: [PATCH 01/16] fix: refs #7917 fix route filter freeLancer --- db/dump/fixtures.before.sql | 14 +++- .../11393-redCamellia/00-firstScript.sql | 17 +++++ modules/route/back/methods/route/filter.js | 9 +++ .../back/methods/route/specs/filter.spec.js | 70 ++++++++++++++++--- 4 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 db/versions/11393-redCamellia/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 97ed0ae47..6a425cf09 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4038,7 +4038,7 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); -INSERT INTO vn.referenceRate (currencyFk, dated, value) +INSERT INTO vn.referenceRate (currencyFk, dated, value) VALUES (2, '2000-12-01', 1.0495), (2, '2001-01-01', 1.0531), (2, '2001-02-01', 7.6347); @@ -4049,3 +4049,15 @@ INSERT IGNORE INTO vn.osrmConfig (id,url,tolerance) INSERT IGNORE INTO vn.inventoryConfig SET id = 1, supplierFk = 4; + +UPDATE vn.worker + SET isFreelance=1 + WHERE firstName='deliveryFreelancer'; + +INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated) + VALUES (132,100,'2001-01-01 00:00:00.000',1,1,'1899-12-30 12:15:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',10.0,1.8,'eighth route',1,0,1,100,'2001-01-01'); +INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated) + VALUES (132,100,'2001-01-01 00:00:00.000',1,2,'1899-12-30 13:20:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',20.0,0.2,'ninth route',9,0,2,100,'2001-01-01'); +UPDATE vn.route + SET workerFk=132 + WHERE id=1; diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql new file mode 100644 index 000000000..6e7499702 --- /dev/null +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -0,0 +1,17 @@ +INSERT INTO account.`role` (name,description,hasLogin,created,modified) + VALUES ('deliveryFreelancer','Repartidor autónomo',1,'2024-07-05 10:18:58.000','2024-07-05 10:18:58.000'); + +-- INSERT INTO account.roleInherit (`role`, inheritsFrom) VALUES(132, 2); +-- CALL account.role_sync(); + +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES + ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('AgencyTerm', 'filter', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route', 'summary', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route', 'getRouteByAgency', 'WRITE', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route','filter','READ','ALLOW','ROLE','deliveryFreelancer'), + ('UserConfig','getUserConfig','*','ALLOW','ROLE','deliveryFreelancer'), + ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'); + diff --git a/modules/route/back/methods/route/filter.js b/modules/route/back/methods/route/filter.js index 70bf7ba67..d4e127a92 100644 --- a/modules/route/back/methods/route/filter.js +++ b/modules/route/back/methods/route/filter.js @@ -87,6 +87,8 @@ module.exports = Self => { Self.filter = async(ctx, filter) => { let conn = Self.dataSource.connector; + const userId = ctx.req.accessToken.userId; + const models = Self.app.models; let where = buildFilter(ctx.args, (param, value) => { switch (param) { @@ -110,6 +112,13 @@ module.exports = Self => { filter = mergeFilters(filter, {where}); + const worker = await models.Worker.findById(userId, {fields: ['isFreelance']}); + const getMyRoute = await models.ACL.checkAccessAcl(ctx, 'Route', 'getRouteByAgency', 'WRITE'); + + if (userId && getMyRoute && worker.isFreelance) { + if (!filter.where) filter.where = {}; + filter.where[`workerFk`] = userId; + } let stmts = []; let stmt; diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index 18c0ca04f..1f21bfa74 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -1,21 +1,39 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; -describe('Route filter()', () => { +fdescribe('Route filter()', () => { const today = Date.vnNew(); today.setHours(2, 0, 0, 0); it('should return the routes matching "search"', async() => { const ctx = { args: { - search: 1, + search: 5, + }, + req: { + accessToken: { + userId: 9 + } + } + }; + const result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].id).toEqual(5); + }); + + it('should return all results matching the filter', async() => { + const ctx = { + req: { + accessToken: { + userId: 132 + } } }; const result = await app.models.Route.filter(ctx); - expect(result.length).toEqual(1); - expect(result[0].id).toEqual(1); + expect(result.length).toEqual(3); }); it('should return results matching "from" and "to"', async() => { @@ -32,12 +50,16 @@ describe('Route filter()', () => { args: { from: from, to: to + }, + req: { + accessToken: { + userId: 9 + } } }; - const results = await models.Route.filter(ctx, options); - expect(results.length).toBe(7); + expect(results.length).toBe(9); await tx.rollback(); } catch (e) { @@ -50,6 +72,11 @@ describe('Route filter()', () => { const ctx = { args: { m3: 0.1, + }, + req: { + accessToken: { + userId: 9 + } } }; @@ -62,6 +89,11 @@ describe('Route filter()', () => { const ctx = { args: { description: 'third route', + }, + req: { + accessToken: { + userId: 9 + } } }; @@ -74,24 +106,33 @@ describe('Route filter()', () => { const ctx = { args: { workerFk: 56, + }, + req: { + accessToken: { + userId: 9 + } } }; - const result = await app.models.Route.filter(ctx); - expect(result.length).toEqual(5); + expect(result.length).toEqual(4); }); it('should return the routes matching "warehouseFk"', async() => { const ctx = { args: { warehouseFk: 1, + }, + req: { + accessToken: { + userId: 9 + } } }; let result = await app.models.Route.filter(ctx); - expect(result.length).toEqual(7); + expect(result.length).toEqual(9); ctx.args.warehouseFk = 2; @@ -104,9 +145,13 @@ describe('Route filter()', () => { const ctx = { args: { vehicleFk: 2, + }, + req: { + accessToken: { + userId: 9 + } } }; - const result = await app.models.Route.filter(ctx); expect(result.length).toEqual(1); @@ -116,6 +161,11 @@ describe('Route filter()', () => { const ctx = { args: { agencyModeFk: 7, + }, + req: { + accessToken: { + userId: 9 + } } }; From 419815ff87914382396524cacbb1ab9c81b2e138 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 23 Dec 2024 11:59:40 +0100 Subject: [PATCH 02/16] fix: refs #7917 fix back --- db/versions/11393-redCamellia/00-firstScript.sql | 3 --- modules/route/back/methods/route/specs/filter.spec.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index 6e7499702..b3ccb880f 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -1,9 +1,6 @@ INSERT INTO account.`role` (name,description,hasLogin,created,modified) VALUES ('deliveryFreelancer','Repartidor autónomo',1,'2024-07-05 10:18:58.000','2024-07-05 10:18:58.000'); --- INSERT INTO account.roleInherit (`role`, inheritsFrom) VALUES(132, 2); --- CALL account.role_sync(); - INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index 1f21bfa74..8f199e34a 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; -fdescribe('Route filter()', () => { +describe('Route filter()', () => { const today = Date.vnNew(); today.setHours(2, 0, 0, 0); From a30cad1da1851924bde0da91e5820d2ec4d37533 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 23 Dec 2024 12:14:16 +0100 Subject: [PATCH 03/16] fix: refs #7917 fix tback --- .../methods/agency-term/specs/filter.spec.js | 12 +- .../back/methods/roadmap/specs/clone.spec.js | 109 ------------------ 2 files changed, 6 insertions(+), 115 deletions(-) delete mode 100644 modules/route/back/methods/roadmap/specs/clone.spec.js diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 41e696157..449028f1e 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -18,7 +18,7 @@ describe('AgencyTerm filter()', () => { const firstAgencyTerm = agencyTerms[0]; expect(firstAgencyTerm.routeFk).toEqual(1); - expect(agencyTerms.length).toEqual(5); + expect(agencyTerms.length).toEqual(7); await tx.rollback(); } catch (e) { @@ -36,7 +36,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(1); + expect(result.length).toEqual(2); expect(result[0].routeFk).toEqual(1); }); @@ -49,7 +49,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(2); + expect(result.length).toEqual(4); }); it('should return results matching "from" and "to"', async() => { @@ -72,7 +72,7 @@ describe('AgencyTerm filter()', () => { const results = await models.AgencyTerm.filter(ctx, options); - expect(results.length).toBe(5); + expect(results.length).toBe(7); await tx.rollback(); } catch (e) { @@ -90,7 +90,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(1); + expect(result.length).toEqual(2); expect(result[0].routeFk).toEqual(1); }); @@ -103,7 +103,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(1); + expect(result.length).toEqual(2); expect(result[0].routeFk).toEqual(2); }); }); diff --git a/modules/route/back/methods/roadmap/specs/clone.spec.js b/modules/route/back/methods/roadmap/specs/clone.spec.js deleted file mode 100644 index 41e696157..000000000 --- a/modules/route/back/methods/roadmap/specs/clone.spec.js +++ /dev/null @@ -1,109 +0,0 @@ -const app = require('vn-loopback/server/server'); -const models = require('vn-loopback/server/server').models; - -describe('AgencyTerm filter()', () => { - const authUserId = 9; - const today = Date.vnNew(); - today.setHours(2, 0, 0, 0); - - it('should return all results matching the filter', async() => { - const tx = await models.AgencyTerm.beginTransaction({}); - - try { - const options = {transaction: tx}; - const filter = {}; - const ctx = {req: {accessToken: {userId: authUserId}}}; - - const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options); - const firstAgencyTerm = agencyTerms[0]; - - expect(firstAgencyTerm.routeFk).toEqual(1); - expect(agencyTerms.length).toEqual(5); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should return results matching "search" searching by integer', async() => { - let ctx = { - args: { - search: 1, - } - }; - - let result = await app.models.AgencyTerm.filter(ctx); - - expect(result.length).toEqual(1); - expect(result[0].routeFk).toEqual(1); - }); - - it('should return results matching "search" searching by string', async() => { - let ctx = { - args: { - search: 'Plants SL', - } - }; - - let result = await app.models.AgencyTerm.filter(ctx); - - expect(result.length).toEqual(2); - }); - - it('should return results matching "from" and "to"', async() => { - const tx = await models.Buy.beginTransaction({}); - const options = {transaction: tx}; - - try { - const from = Date.vnNew(); - from.setHours(0, 0, 0, 0); - - const to = Date.vnNew(); - to.setHours(23, 59, 59, 999); - - const ctx = { - args: { - from: from, - to: to - } - }; - - const results = await models.AgencyTerm.filter(ctx, options); - - expect(results.length).toBe(5); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should return results matching "agencyModeFk"', async() => { - let ctx = { - args: { - agencyModeFk: 1, - } - }; - - let result = await app.models.AgencyTerm.filter(ctx); - - expect(result.length).toEqual(1); - expect(result[0].routeFk).toEqual(1); - }); - - it('should return results matching "agencyFk"', async() => { - let ctx = { - args: { - agencyFk: 2, - } - }; - - let result = await app.models.AgencyTerm.filter(ctx); - - expect(result.length).toEqual(1); - expect(result[0].routeFk).toEqual(2); - }); -}); From 16bbcf8185120fbc5347ef787832db6fcbc77427 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 23 Dec 2024 12:18:40 +0100 Subject: [PATCH 04/16] fix: refs #7917 fix summary test --- modules/route/back/methods/route/specs/summary.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/route/back/methods/route/specs/summary.spec.js b/modules/route/back/methods/route/specs/summary.spec.js index a9516f7c5..096abe62c 100644 --- a/modules/route/back/methods/route/specs/summary.spec.js +++ b/modules/route/back/methods/route/specs/summary.spec.js @@ -25,7 +25,7 @@ describe('route summary()', () => { const result = await app.models.Route.summary(1); const worker = result.route.worker().user(); - expect(worker.name).toEqual('delivery'); + expect(worker.name).toEqual('deliveryfreelancer'); }); it(`should return a summary object containing data from the tickets`, async() => { From 85163a13fa72790b9da63e40735c5a411f3d8a4d Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 24 Dec 2024 08:13:00 +0100 Subject: [PATCH 05/16] fix: refs #7917 fix fixtures --- db/dump/fixtures.before.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 6a425cf09..fba3b3487 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -754,6 +754,8 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()); + (8, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (9, '1899-12-30 13:20:00', 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`, `problem`, `risk`) VALUES From 78a8f80321139bbf6c405581a94b692d458012d8 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 2 Jan 2025 08:38:24 +0100 Subject: [PATCH 06/16] fix: refs #7917 fix tback --- db/dump/fixtures.before.sql | 6 +----- modules/route/back/methods/agency-term/specs/filter.spec.js | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 0593eda92..d62248dfd 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -753,7 +753,7 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen (4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12, util.VN_CURDATE()), (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), - (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()); + (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()), (8, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), (9, '1899-12-30 13:20:00', 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); @@ -4060,10 +4060,6 @@ UPDATE vn.worker SET isFreelance=1 WHERE firstName='deliveryFreelancer'; -INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated) - VALUES (132,100,'2001-01-01 00:00:00.000',1,1,'1899-12-30 12:15:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',10.0,1.8,'eighth route',1,0,1,100,'2001-01-01'); -INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated) - VALUES (132,100,'2001-01-01 00:00:00.000',1,2,'1899-12-30 13:20:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',20.0,0.2,'ninth route',9,0,2,100,'2001-01-01'); UPDATE vn.route SET workerFk=132 WHERE id=1; diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 449028f1e..aa2743868 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -36,7 +36,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(2); + expect(result.length).toEqual(1); expect(result[0].routeFk).toEqual(1); }); From 86dde8dfb3a92112529fec716725c3359d3d0a64 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 14 Jan 2025 07:18:05 +0100 Subject: [PATCH 07/16] fix: refs #7917 fix pr --- db/dump/fixtures.before.sql | 4 ++-- db/versions/11393-redCamellia/00-firstScript.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index d62248dfd..e2d8ca425 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -754,8 +754,8 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()), - (8, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), - (9, '1899-12-30 13:20:00', 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); + (8, NULL, 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (9, NULL, 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`, `problem`, `risk`) VALUES diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index b3ccb880f..ae6c909e8 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -1,5 +1,5 @@ -INSERT INTO account.`role` (name,description,hasLogin,created,modified) - VALUES ('deliveryFreelancer','Repartidor autónomo',1,'2024-07-05 10:18:58.000','2024-07-05 10:18:58.000'); +INSERT INTO account.`role` (name,description,hasLogin) + VALUES ('deliveryFreelancer','Repartidor autónomo',1); INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES From 516147b8bb4f2ded4c2bc747f328f340c6eadcb8 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 15 Jan 2025 13:04:49 +0100 Subject: [PATCH 08/16] fix: refs #7917 fix acls --- db/versions/11393-redCamellia/00-firstScript.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index ae6c909e8..c8f13fe69 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -10,5 +10,7 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p ('Route','filter','READ','ALLOW','ROLE','deliveryFreelancer'), ('UserConfig','getUserConfig','*','ALLOW','ROLE','deliveryFreelancer'), ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route','guessPriority','WRITE','ALLOW','ROLE','deliveryFreelancer'), + ('Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryFreelancer'), ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'); From d66b8f49637d3d7a1cccb7d0c1fdc5586d082151 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 21 Jan 2025 13:54:02 +0100 Subject: [PATCH 09/16] fix: refs #7917 acls --- db/versions/11393-redCamellia/00-firstScript.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index c8f13fe69..c7a2488c1 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -12,5 +12,6 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), ('Route','guessPriority','WRITE','ALLOW','ROLE','deliveryFreelancer'), ('Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryFreelancer'), - ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'); - + ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Ticket','sendSms','WRITE','ALLOW','ROLE','deliveryFreelancer'), + ('Ticket','upsert','WRITE','ALLOW','ROLE','deliveryFreelancer'); From 99b5433e624dcc518f37abb5990558a78d00b57e Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 22 Jan 2025 10:02:20 +0100 Subject: [PATCH 10/16] fix: refs #7917 fix acls --- db/versions/11393-redCamellia/00-firstScript.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index c7a2488c1..19ea2a9ef 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -13,5 +13,7 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p ('Route','guessPriority','WRITE','ALLOW','ROLE','deliveryFreelancer'), ('Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryFreelancer'), ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), - ('Ticket','sendSms','WRITE','ALLOW','ROLE','deliveryFreelancer'), - ('Ticket','upsert','WRITE','ALLOW','ROLE','deliveryFreelancer'); + ('Route','sendSms','WRITE','ALLOW','ROLE','deliveryFreelancer'), + ('Ticket','updateAttributes','WRITE','ALLOW','ROLE','deliveryFreelancer'), + ('Client','findById','READ','ALLOW','ROLE','deliveryFreelancer'); +; From c4a7fbf6e82066a3e15e1452469ee82a2a5cf79e Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 Jan 2025 10:57:54 +0100 Subject: [PATCH 11/16] fix: refs #7917 fix tests --- db/dump/fixtures.before.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 00fa54281..1622a48c1 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -747,7 +747,7 @@ INSERT INTO `vn`.`zoneConfig` (`id`, `scope`) VALUES (1, '1'); INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`, `dated`) VALUES - (1, '1899-12-30 12:15:00', 56, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (1, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), (2, '1899-12-30 13:20:00', 56, util.VN_CURDATE(), 1, 2, 'second route', 0.2, 20, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()), (3, '1899-12-30 14:30:00', 56, util.VN_CURDATE(), 2, 3, 'third route', 0.5, 30, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 10, util.VN_CURDATE()), (4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12, util.VN_CURDATE()), From d659e05ce854dd73d7d103c59b1c936bf31a8925 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 Jan 2025 11:46:29 +0100 Subject: [PATCH 12/16] fix: refs #7917 remove update --- db/dump/fixtures.before.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 1622a48c1..2e73ef7df 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4063,6 +4063,3 @@ UPDATE vn.worker SET isFreelance=1 WHERE firstName='deliveryFreelancer'; -UPDATE vn.route - SET workerFk=132 - WHERE id=1; From a01c419b44f2633ef74a8786f877d6b63d92028b Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 28 Jan 2025 12:51:21 +0100 Subject: [PATCH 13/16] fix: refs #7917 fix tback --- modules/route/back/methods/route/specs/summary.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/route/back/methods/route/specs/summary.spec.js b/modules/route/back/methods/route/specs/summary.spec.js index 096abe62c..2ef052c7e 100644 --- a/modules/route/back/methods/route/specs/summary.spec.js +++ b/modules/route/back/methods/route/specs/summary.spec.js @@ -22,10 +22,10 @@ describe('route summary()', () => { }); it(`should return a summary object containing it's worker`, async() => { - const result = await app.models.Route.summary(1); + const result = await app.models.Route.summary(2); const worker = result.route.worker().user(); - expect(worker.name).toEqual('deliveryfreelancer'); + expect(worker.name).toEqual('delivery'); }); it(`should return a summary object containing data from the tickets`, async() => { From b383725f9fa3311ef26fdc19864507c084803939 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 28 Jan 2025 12:56:30 +0100 Subject: [PATCH 14/16] fix: refs #7917 fix user tests --- db/dump/fixtures.before.sql | 6 +++--- modules/route/back/methods/route/specs/filter.spec.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 0d3029cfe..76ccc7c1e 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -752,15 +752,15 @@ INSERT INTO `vn`.`zoneConfig` (`id`, `scope`) VALUES (1, '1'); INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`, `dated`) VALUES - (1, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (1, '1899-12-30 12:15:00', 133, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), (2, '1899-12-30 13:20:00', 56, util.VN_CURDATE(), 1, 2, 'second route', 0.2, 20, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()), (3, '1899-12-30 14:30:00', 56, util.VN_CURDATE(), 2, 3, 'third route', 0.5, 30, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 10, util.VN_CURDATE()), (4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12, util.VN_CURDATE()), (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()), - (8, NULL, 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), - (9, NULL, 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); + (8, NULL, 133, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (9, NULL, 133, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`, `problem`, `risk`) VALUES diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index 8f199e34a..11bf0b7b0 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -26,7 +26,7 @@ describe('Route filter()', () => { const ctx = { req: { accessToken: { - userId: 132 + userId: 133 } } }; From 801629c8dbd50ef44eb29650b13355f868873bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 28 Jan 2025 18:04:02 +0100 Subject: [PATCH 15/16] fix: refs #8492 Sage invoiceInTax Check VAT --- .../procedures/accountingMovements_add.sql | 65 ++++++++++++------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/db/routines/sage/procedures/accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql index 8c129beb2..060d89a3f 100644 --- a/db/routines/sage/procedures/accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -1,11 +1,11 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`accountingMovements_add`( - vYear INT, + vYear INT, vCompanyFk INT ) BEGIN /** - * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta + * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta * para poder ejecutar posteriormente el proceso de importación de datos de SQL Server * Solo traladará los asientos marcados con el campo vn.XDiario.enlazadoSage = FALSE * @vYear Año contable del que se quiere trasladar la información @@ -23,6 +23,7 @@ BEGIN DECLARE vInvoiceTypeInformativeCode VARCHAR(1); DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); DECLARE vCompanyCode INT; + DECLARE vHasErrorTax BOOL DEFAULT FALSE; SELECT SiglaNacion INTO vCountryCanariasCode FROM Naciones @@ -44,12 +45,12 @@ BEGIN FROM taxType WHERE code = 'import4'; - SELECT shipmentTransactionTypeFk, - definitiveExportTransactionTypeFk, + SELECT shipmentTransactionTypeFk, + definitiveExportTransactionTypeFk, pendingServiceTransactionTypeFk, company_getCode(vCompanyFk) INTO vTransactionExportTaxFreeFk, - vTransactionExportFk, + vTransactionExportFk, vDuaTransactionFk, vCompanyCode FROM config; @@ -66,6 +67,24 @@ BEGIN WHERE enlazadoSage = FALSE AND Asiento <> 1 ; + SELECT EXISTS ( + SELECT TRUE + FROM vn.XDiario x + JOIN vn.invoiceIn ii ON ii.id = x.CLAVE + JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id + LEFT JOIN TiposIva ti ON ti.CodigoIva = it.taxTypeSageFk + LEFT JOIN taxType tt ON tt.id = it.taxTypeSageFk + WHERE x.FECHA BETWEEN vDatedFrom AND vDatedTo + AND NOT x.enlazadoSage + AND x.empresa_id = vCompanyFk + AND it.taxTypeSageFk + AND (ti.CodigoIva IS NULL OR tt.id IS NULL) + ) INTO vHasErrorTax; + + IF vHasErrorTax tHEN + CALL util.throw ('Error in tables for received invoices tax'); + END IF; + CALL invoiceOut_manager(vYear, vCompanyFk); CALL invoiceIn_manager(vYear, vCompanyFk); @@ -306,8 +325,8 @@ BEGIN mci.FechaFacturaOriginal = x.FECHA_EX, mci.SuFacturaNo = x.FACTURAEX, mci.FechaOperacion = x.FECHA_OP, - mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -326,7 +345,7 @@ BEGIN mci.CodigoIva2 = vTaxImportFk, mci.IvaDeducible2 = TRUE, mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -344,8 +363,8 @@ BEGIN mci.CodigoTransaccion3 = vDuaTransactionFk , mci.CodigoIva3 = vTaxImportSuperReducedFk, mci.IvaDeducible3 = TRUE, - mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -379,14 +398,14 @@ BEGIN OR CodigoTransaccion2 = vTransactionExportFk OR CodigoTransaccion3 = vTransactionExportFk OR CodigoTransaccion4 = vTransactionExportFk) - AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, + AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, vCountryCeutaMelillaCode COLLATE utf8mb3_unicode_ci); UPDATE movConta mc SET CodigoDivisa = 'USD', FactorCambio = TRUE, - ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, - ImporteAsiento / ImporteDivisa, + ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, + ImporteAsiento / ImporteDivisa, ImporteCambio) AS DECIMAL( 10, 2))) WHERE enlazadoSage = FALSE AND (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio); @@ -403,20 +422,20 @@ BEGIN WITH client AS( SELECT DISTINCT c.id FROM sage.movConta mc - JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta - WHERE NOT enlazadoSage - ),supplier AS( + JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta + WHERE NOT enlazadoSage + ),supplier AS( SELECT DISTINCT s.id FROM sage.movConta mc - JOIN vn.supplier s ON s.account = mc.CodigoCuenta - WHERE NOT enlazadoSage + JOIN vn.supplier s ON s.account = mc.CodigoCuenta + WHERE NOT enlazadoSage ),clientSupplierSync AS( SELECT idClientSupplier, `type` - FROM sage.clientSupplier cs - WHERE isSync + FROM sage.clientSupplier cs + WHERE isSync ) SELECT idClientSupplier, `type` - FROM sage.clientSupplier cs + FROM sage.clientSupplier cs WHERE NOT isSync UNION SELECT id, 'C' @@ -424,7 +443,7 @@ BEGIN LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = c.id AND cs.Type ='C' WHERE cs.idClientSupplier IS NULL - UNION + UNION SELECT id, 'P' FROM supplier s LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = s.id @@ -436,7 +455,7 @@ BEGIN INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync) SELECT vCompanyCode, `type`, idClientSupplier, FALSE FROM tmp.clientSupplier; - + DROP TEMPORARY TABLE tmp.clientSupplier; CALL pgc_add(vCompanyFk); From 1d53f2c49073fde57547da7c79b2d6cb3d6b27a5 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 29 Jan 2025 11:43:15 +0100 Subject: [PATCH 16/16] fix: worker filter limit --- modules/worker/back/methods/worker/filter.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/worker/back/methods/worker/filter.js b/modules/worker/back/methods/worker/filter.js index 087f080bd..da12dceca 100644 --- a/modules/worker/back/methods/worker/filter.js +++ b/modules/worker/back/methods/worker/filter.js @@ -166,12 +166,11 @@ module.exports = Self => { LEFT JOIN account.emailUser eu ON eu.userFk = u.id` ); - stmt.merge(conn.makeWhere(filter.where)); - stmts.push(stmt); + stmt.merge(conn.makeSuffix(filter)); + let itemsIndex = stmts.push(stmt) - 1; - const itemsIndex = stmts.push(stmt) - 1; - const sql = ParameterizedSQL.join(stmts, ';'); - const result = await conn.executeStmt(sql, myOptions); - return result[itemsIndex]; + let sql = ParameterizedSQL.join(stmts, ';'); + let result = await conn.executeStmt(sql); + return itemsIndex === 0 ? result : result[itemsIndex]; }; };