From 30c896c975adec36486be7386aef9d79919bc176 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 May 2023 11:20:07 +0200 Subject: [PATCH 1/3] refs #5678 feat(sale_canEdit): handle exist sale --- loopback/locale/es.json | 3 +- modules/ticket/back/methods/sale/canEdit.js | 5 ++- .../back/methods/sale/specs/canEdit.spec.js | 42 +++++++++++++------ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 45993bdd5..956e66985 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -84,6 +84,7 @@ "The current ticket can't be modified": "El ticket actual no puede ser modificado", "The current claim can't be modified": "La reclamación actual no puede ser modificada", "The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas", + "The sales do not exist": "La(s) linea(s) seleccionada no(s) exite(n)", "Please select at least one sale": "Por favor selecciona al menos una linea", "All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket", "NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada", @@ -291,4 +292,4 @@ "comercialId": "Id comercial", "comercialName": "Comercial", "Invalid NIF for VIES": "Invalid NIF for VIES" -} \ No newline at end of file +} diff --git a/modules/ticket/back/methods/sale/canEdit.js b/modules/ticket/back/methods/sale/canEdit.js index 3091ebca7..df0a939bf 100644 --- a/modules/ticket/back/methods/sale/canEdit.js +++ b/modules/ticket/back/methods/sale/canEdit.js @@ -38,6 +38,9 @@ module.exports = Self => { } }, myOptions); + if (!salesData.length) + throw new UserError(`The sales do not exist`); + const ticketId = salesData[0].ticketFk; const isTicketEditable = await models.Ticket.isEditable(ctx, ticketId, myOptions); @@ -62,7 +65,5 @@ module.exports = Self => { throw new UserError('It is not possible to modify cloned sales'); if (!shouldEditFloramondo) throw new UserError('It is not possible to modify sales that their articles are from Floramondo'); - - return true; }; }; diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index 62f98421a..c12277e80 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -17,6 +17,32 @@ describe('sale canEdit()', () => { }); }); + describe('sale not exist', () => { + it('should return error if sale not exist', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const developerId = 9; + const ctx = {req: {accessToken: {userId: developerId}}}; + + let max = await models.Sale.findOne({fields: ['id'], order: 'id DESC'}, options); + max.id = max.id + 1; + + const sales = [max.id]; + await models.Sale.canEdit(ctx, sales, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e.message; + } + + expect(error).toEqual('The sales do not exist'); + }); + }); + describe('sale editTracked', () => { it('should return true if the role is production regardless of the saleTrackings', async() => { const tx = await models.Sale.beginTransaction({}); @@ -29,9 +55,7 @@ describe('sale canEdit()', () => { const sales = [25]; - const result = await models.Sale.canEdit(ctx, sales, options); - - expect(result).toEqual(true); + await models.Sale.canEdit(ctx, sales, options); await tx.rollback(); } catch (e) { @@ -51,9 +75,7 @@ describe('sale canEdit()', () => { const sales = [10]; - const result = await models.Sale.canEdit(ctx, sales, options); - - expect(result).toEqual(true); + await models.Sale.canEdit(ctx, sales, options); await tx.rollback(); } catch (e) { @@ -87,9 +109,7 @@ describe('sale canEdit()', () => { }); const ctx = {req: {accessToken: {userId: role.id}}}; - const result = await models.Sale.canEdit(ctx, saleCloned, options); - - expect(result).toEqual(true); + await models.Sale.canEdit(ctx, saleCloned, options); await tx.rollback(); } catch (e) { @@ -150,9 +170,7 @@ describe('sale canEdit()', () => { const saleToEdit = await models.Sale.findById(sales[0], null, options); await saleToEdit.updateAttribute('itemFk', 9, options); - const result = await models.Sale.canEdit(ctx, sales, options); - - expect(result).toEqual(true); + await models.Sale.canEdit(ctx, sales, options); await tx.rollback(); } catch (e) { From 6b66eb3bb279f333b3a84ec963cdfa3ae75984bf Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 May 2023 12:59:58 +0200 Subject: [PATCH 2/3] refs #5679 typo --- loopback/locale/es.json | 2 +- modules/ticket/back/methods/sale/canEdit.js | 2 +- modules/ticket/back/methods/sale/specs/canEdit.spec.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 956e66985..e5a7ba3f5 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -84,7 +84,7 @@ "The current ticket can't be modified": "El ticket actual no puede ser modificado", "The current claim can't be modified": "La reclamación actual no puede ser modificada", "The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas", - "The sales do not exist": "La(s) linea(s) seleccionada no(s) exite(n)", + "The sales do not exists": "La(s) linea(s) seleccionada(s) no exite(n)", "Please select at least one sale": "Por favor selecciona al menos una linea", "All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket", "NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada", diff --git a/modules/ticket/back/methods/sale/canEdit.js b/modules/ticket/back/methods/sale/canEdit.js index df0a939bf..cb3f2420a 100644 --- a/modules/ticket/back/methods/sale/canEdit.js +++ b/modules/ticket/back/methods/sale/canEdit.js @@ -39,7 +39,7 @@ module.exports = Self => { }, myOptions); if (!salesData.length) - throw new UserError(`The sales do not exist`); + throw new UserError(`The sales do not exists`); const ticketId = salesData[0].ticketFk; diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index c12277e80..eef9136a8 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -17,8 +17,8 @@ describe('sale canEdit()', () => { }); }); - describe('sale not exist', () => { - it('should return error if sale not exist', async() => { + describe('sale not exists', () => { + it('should return error if sale not exists', async() => { const tx = await models.Sale.beginTransaction({}); try { @@ -39,7 +39,7 @@ describe('sale canEdit()', () => { error = e.message; } - expect(error).toEqual('The sales do not exist'); + expect(error).toEqual('The sales do not exists'); }); }); From 292d9e038d3479517754ee85d7c68d0e547fcd28 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 May 2023 13:38:11 +0200 Subject: [PATCH 3/3] typo --- loopback/locale/es.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index e5a7ba3f5..4f45b0cb2 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -84,7 +84,7 @@ "The current ticket can't be modified": "El ticket actual no puede ser modificado", "The current claim can't be modified": "La reclamación actual no puede ser modificada", "The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas", - "The sales do not exists": "La(s) linea(s) seleccionada(s) no exite(n)", + "The sales do not exists": "La(s) línea(s) seleccionada(s) no existe(n)", "Please select at least one sale": "Por favor selecciona al menos una linea", "All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket", "NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada",