hotfix creditClient
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Carlos Satorres 2024-02-15 12:59:30 +01:00
parent cc24ecdc7d
commit 98d2b5a0ff
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) {
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();

View File

@ -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;
}
});
});

View File

@ -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 = {};