From 59ea47a8c33acf5d4de6beea36a46eeb9248c282 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 16 Feb 2024 13:06:33 +0100 Subject: [PATCH 1/6] refs #6414 tback --- .../back/methods/worker/specs/new.spec.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index d0830b00f..f5deb86ef 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -36,6 +36,26 @@ describe('Worker new', () => { payMethodFk: 1, roleFk: 1 }; + + const clientWorker = { + fi: '09412983A', + name: 'CLIENTWORKER', + firstName: 'CLIENT', + lastNames: 'WORKER', + email: 'clientWorker@mydomain.com', + street: 'S/ DEFAULTWORKERSTREET', + city: 'defaultWorkerCity', + provinceFk: 1, + companyFk: 442, + postcode: '46680', + phone: '123456489', + code: 'CCW', + bossFk: 9, + birth: '2022-12-11T23:00:00.000Z', + payMethodFk: 1, + roleFk: 1 + }; + const req = {accessToken: {userId: 9}}; it('should return error if personal mail already exists', async() => { @@ -149,6 +169,18 @@ describe('Worker new', () => { expect(newWorker.id).toBeDefined(); }); + it('should create a new client', async() => { + const newWorker = await models.Worker.new({args: clientWorker, req}); + + await models.Worker.destroyById(newWorker.id); + await models.Address.destroyAll({clientFk: newWorker.id}); + await models.Mandate.destroyAll({clientFk: newWorker.id}); + await models.Client.destroyById(newWorker.id); + await models.VnUser.destroyById(newWorker.id); + + expect(newWorker.id).toBeDefined(); + }); + it('should create a new worker in client', async() => { const bruceWayneId = 1101; const client = await models.Client.findById(bruceWayneId, {fields: ['fi', 'email']}); From f3511d4a43b010e273668a861fa84d994d95b94b Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 20 Feb 2024 09:53:28 +0100 Subject: [PATCH 2/6] refs #6414 tback --- .../back/methods/worker/specs/new.spec.js | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index f5deb86ef..1f74e9b95 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -37,25 +37,6 @@ describe('Worker new', () => { roleFk: 1 }; - const clientWorker = { - fi: '09412983A', - name: 'CLIENTWORKER', - firstName: 'CLIENT', - lastNames: 'WORKER', - email: 'clientWorker@mydomain.com', - street: 'S/ DEFAULTWORKERSTREET', - city: 'defaultWorkerCity', - provinceFk: 1, - companyFk: 442, - postcode: '46680', - phone: '123456489', - code: 'CCW', - bossFk: 9, - birth: '2022-12-11T23:00:00.000Z', - payMethodFk: 1, - roleFk: 1 - }; - const req = {accessToken: {userId: 9}}; it('should return error if personal mail already exists', async() => { @@ -160,25 +141,22 @@ describe('Worker new', () => { it('should create a new worker', async() => { const newWorker = await models.Worker.new({args: defaultWorker, req}); - await models.Worker.destroyById(newWorker.id); - await models.Address.destroyAll({clientFk: newWorker.id}); - await models.Mandate.destroyAll({clientFk: newWorker.id}); - await models.Client.destroyById(newWorker.id); - await models.VnUser.destroyById(newWorker.id); + await removeWorker(newWorker.id); expect(newWorker.id).toBeDefined(); }); it('should create a new client', async() => { - const newWorker = await models.Worker.new({args: clientWorker, req}); + let newWorker; + let client; + try { + newWorker = await models.Worker.new({args: defaultWorker, req}); + client = await models.Client.findById(newWorker.id); + } finally { + await removeWorker(newWorker.id); + } - await models.Worker.destroyById(newWorker.id); - await models.Address.destroyAll({clientFk: newWorker.id}); - await models.Mandate.destroyAll({clientFk: newWorker.id}); - await models.Client.destroyById(newWorker.id); - await models.VnUser.destroyById(newWorker.id); - - expect(newWorker.id).toBeDefined(); + expect(client).toBeDefined(); }); it('should create a new worker in client', async() => { @@ -202,3 +180,11 @@ describe('Worker new', () => { expect(newWorker.id).toEqual(bruceWayneId); }); }); + +async function removeWorker(id) { + await models.Worker.destroyById(id); + await models.Address.destroyAll({clientFk: id}); + await models.Mandate.destroyAll({clientFk: id}); + await models.Client.destroyById(id); + await models.VnUser.destroyById(id); +} From b9fe9900035ba3629c7f77145faea176398bed40 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 20 Feb 2024 16:10:16 +0100 Subject: [PATCH 3/6] refs #6834 feat:handle Error --- .../sectorCollectionSaleGroup_add.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index 9e21defc5..2ef932384 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -8,6 +8,25 @@ BEGIN * @param vSaleGroupFk Identificador de vn.saleGroup * @param vSectorCollectionFk Identificador de vn.sectorCollection */ + DECLARE vHasSaleGroup INT; + DECLARE vHasSectorCollection INT; + + SELECT COUNT(id) INTO vHasSaleGroup + FROM vn.saleGroup sg + WHERE sg.id = vSaleGroupFk; + + IF !vHasSaleGroup THEN + CALL util.Throw ("INVALID_SALEGROUP"); + END IF; + + SELECT COUNT(id) INTO vHasSectorCollection + FROM vn.sectorCollection scsg + WHERE scsg.id = vSectorCollectionFk; + + IF !vHasSectorCollection THEN + CALL util.Throw ("INVALID_SECTORCOLLECTION"); + END IF; + REPLACE sectorCollectionSaleGroup SET sectorCollectionFk = vSectorCollectionFk, saleGroupFk = vSaleGroupFk; From be81835474b39e34dc9aadd10cc1d2d8d7725008 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 20 Feb 2024 16:11:59 +0100 Subject: [PATCH 4/6] refs #6834 feat:handle Error --- db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index 2ef932384..eb720f31e 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -16,7 +16,7 @@ BEGIN WHERE sg.id = vSaleGroupFk; IF !vHasSaleGroup THEN - CALL util.Throw ("INVALID_SALEGROUP"); + CALL util.throw ("INVALID_SALEGROUP"); END IF; SELECT COUNT(id) INTO vHasSectorCollection @@ -24,7 +24,7 @@ BEGIN WHERE scsg.id = vSectorCollectionFk; IF !vHasSectorCollection THEN - CALL util.Throw ("INVALID_SECTORCOLLECTION"); + CALL util.throw ("INVALID_SECTORCOLLECTION"); END IF; REPLACE sectorCollectionSaleGroup From 614652c35725fa7a4a5cbf08c0e08b1c56317663 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 21 Feb 2024 07:08:45 +0100 Subject: [PATCH 5/6] refs #6834 feat:handle Error --- .../vn/procedures/sectorCollectionSaleGroup_add.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index eb720f31e..999229d64 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -12,19 +12,19 @@ BEGIN DECLARE vHasSectorCollection INT; SELECT COUNT(id) INTO vHasSaleGroup - FROM vn.saleGroup sg - WHERE sg.id = vSaleGroupFk; + FROM vn.saleGroup + WHERE id = vSaleGroupFk; IF !vHasSaleGroup THEN - CALL util.throw ("INVALID_SALEGROUP"); + CALL util.throw ("invalid saleGroup"); END IF; SELECT COUNT(id) INTO vHasSectorCollection - FROM vn.sectorCollection scsg - WHERE scsg.id = vSectorCollectionFk; + FROM vn.sectorCollection + WHERE id = vSectorCollectionFk; IF !vHasSectorCollection THEN - CALL util.throw ("INVALID_SECTORCOLLECTION"); + CALL util.throw ("invalid sectorCollection"); END IF; REPLACE sectorCollectionSaleGroup From 448763ee725a0810df9ae59c391bdbd3c7c631fa Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 21 Feb 2024 07:15:43 +0100 Subject: [PATCH 6/6] refs #6834 feat:handle Error --- db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql index 999229d64..5ffb30635 100644 --- a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -12,7 +12,7 @@ BEGIN DECLARE vHasSectorCollection INT; SELECT COUNT(id) INTO vHasSaleGroup - FROM vn.saleGroup + FROM saleGroup WHERE id = vSaleGroupFk; IF !vHasSaleGroup THEN @@ -20,7 +20,7 @@ BEGIN END IF; SELECT COUNT(id) INTO vHasSectorCollection - FROM vn.sectorCollection + FROM sectorCollection WHERE id = vSectorCollectionFk; IF !vHasSectorCollection THEN