From 98d2b5a0ffcfd3a7099c12955c0105867a2ebd04 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 15 Feb 2024 12:59:30 +0100 Subject: [PATCH] hotfix creditClient --- .../client/back/methods/client/setRating.js | 2 +- .../methods/client/specs/setRating.spec.js | 22 +++++++++++++++++++ modules/client/back/models/client.js | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/setRating.js b/modules/client/back/methods/client/setRating.js index 21ac0c914..e3f866683 100644 --- a/modules/client/back/methods/client/setRating.js +++ b/modules/client/back/methods/client/setRating.js @@ -28,7 +28,6 @@ module.exports = Self => { Self.setRating = async function(ctx, id, rating, recommendedCredit, options) { let tx; const myOptions = {}; - if (typeof options == 'object') Object.assign(myOptions, options); @@ -42,6 +41,7 @@ module.exports = Self => { const clientUpdated = await client.updateAttributes({ rating: rating, recommendedCredit: recommendedCredit + }, myOptions); if (tx) await tx.commit(); diff --git a/modules/client/back/methods/client/specs/setRating.spec.js b/modules/client/back/methods/client/specs/setRating.spec.js index a7d0fb03a..353095e31 100644 --- a/modules/client/back/methods/client/specs/setRating.spec.js +++ b/modules/client/back/methods/client/specs/setRating.spec.js @@ -40,4 +40,26 @@ describe('Client setRating()', () => { throw e; } }); + + it('should change rating and recommendedCredit to 0', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const clientId = 1101; + const newRating = 0; + const newRecommendedCredit = 0; + + const updatedClient = await models.Client.setRating(ctx, clientId, newRating, newRecommendedCredit, options); + + expect(updatedClient.rating).toEqual(newRating); + expect(updatedClient.recommendedCredit).toEqual(newRecommendedCredit); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index a9e14effa..0a8ebcae5 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -319,7 +319,8 @@ module.exports = Self => { await Self.changeCredit(ctx, finalState, changes); // Credit management changes - if (changes?.rating || changes?.recommendedCredit) + + if (changes?.rating >= 0 || changes?.recommendedCredit >= 0) await Self.changeCreditManagement(ctx, finalState, changes); const oldInstance = {};