WEB-536:fix: resolve chargeIds parameter error in penalty waiving (#2957)

This commit is contained in:
Shubham Kumar
2026-01-01 15:43:32 -06:00
committed by GitHub
parent b00c60ef27
commit c28f729363
3 changed files with 60 additions and 6 deletions
@@ -126,11 +126,25 @@ export class LoanRescheduleComponent implements OnInit {
};
data.loanId = this.loanId;
// Add waived penalty charge IDs if penalties are being waived
// Waive penalties first if selected, then submit reschedule
if (this.waivePenalties.value && this.selectedPenalties.length > 0) {
data.chargeIds = this.selectedPenalties;
this.penaltyManagementService.waivePenalties(this.loanId, this.selectedPenalties).subscribe({
next: () => {
this.submitReschedule(data);
},
error: (error: any) => {
console.error('Error waiving penalties:', error);
// Continue with reschedule even if waive fails
this.submitReschedule(data);
}
});
} else {
this.submitReschedule(data);
}
}
/** Submit the reschedule after penalties are waived */
private submitReschedule(data: any) {
this.loanService.submitRescheduleData(data).subscribe((response: any) => {
// TODO: needs to be updated
// mentioned in Community App:
@@ -326,11 +326,25 @@ export class MakeRepaymentComponent implements OnInit {
}
delete data.skipInterestRefund;
// Add waived penalty charge IDs if penalties are being waived
// Waive penalties first if selected, then submit repayment
if (this.waivePenalties && this.selectedPenalties.length > 0) {
data.chargeIds = this.selectedPenalties;
this.penaltyManagementService.waivePenalties(this.loanId, this.selectedPenalties).subscribe({
next: () => {
this.submitRepayment(data);
},
error: (error: any) => {
console.error('Error waiving penalties:', error);
// Continue with repayment even if waive fails
this.submitRepayment(data);
}
});
} else {
this.submitRepayment(data);
}
}
/** Submit the repayment after penalties are waived */
private submitRepayment(data: any) {
this.loanService.submitLoanActionButton(this.loanId, data, this.command).subscribe((response: any) => {
this.router.navigate(['../../transactions'], { relativeTo: this.route });
});
@@ -1,6 +1,6 @@
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Observable, forkJoin, of } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { LoansService } from '../loans.service';
import { Dates } from 'app/core/utils/dates';
@@ -187,4 +187,30 @@ export class PenaltyManagementService {
// Fall back to the raw name (translate pipe will no-op if not a key)
return rawName;
}
/**
* Waive selected penalties for a loan
* Uses the existing executeLoansAccountChargesCommand API with 'waive' command
* @param loanId The loan ID
* @param penaltyIds Array of penalty/charge IDs to waive
* @returns Observable that completes when all penalties are waived
*/
waivePenalties(loanId: string, penaltyIds: number[]): Observable<any[]> {
if (!penaltyIds || penaltyIds.length === 0) {
return of([]);
}
// Create waive requests for each penalty
const waiveRequests = penaltyIds.map((chargeId: number) =>
this.loanService.executeLoansAccountChargesCommand(loanId, 'waive', {}, chargeId).pipe(
catchError((error: any) => {
console.error(`Error waiving penalty ${chargeId}:`, error);
// Return null for failed waive operations so we can continue with others
return of(null);
})
)
);
return forkJoin(waiveRequests);
}
}