hotfix creditClient #2041

Merged
carlossa merged 1 commits from hotfix-creditClient into master 2024-02-15 15:25:47 +00:00
3 changed files with 25 additions and 2 deletions

View File

@ -28,7 +28,6 @@ module.exports = Self => {
Self.setRating = async function(ctx, id, rating, recommendedCredit, options) { Self.setRating = async function(ctx, id, rating, recommendedCredit, options) {
let tx; let tx;
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -42,6 +41,7 @@ module.exports = Self => {
const clientUpdated = await client.updateAttributes({ const clientUpdated = await client.updateAttributes({
rating: rating, rating: rating,
recommendedCredit: recommendedCredit recommendedCredit: recommendedCredit
}, myOptions); }, myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();

View File

@ -40,4 +40,26 @@ describe('Client setRating()', () => {
throw e; 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;
}
});
}); });

View File

@ -319,7 +319,8 @@ module.exports = Self => {
await Self.changeCredit(ctx, finalState, changes); await Self.changeCredit(ctx, finalState, changes);
// Credit management changes // Credit management changes
if (changes?.rating || changes?.recommendedCredit)
if (changes?.rating >= 0 || changes?.recommendedCredit >= 0)
await Self.changeCreditManagement(ctx, finalState, changes); await Self.changeCreditManagement(ctx, finalState, changes);
const oldInstance = {}; const oldInstance = {};