Skip to content

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

Merged
IOhacker merged 1 commit intoopenMF:devfrom
shubhamkumar9199:fix/loan-penalty-waiving-chargeids-error
Jan 1, 2026
Merged

WEB-536:fix resolve chargeIds parameter error in penalty waiving#2957
IOhacker merged 1 commit intoopenMF:devfrom
shubhamkumar9199:fix/loan-penalty-waiving-chargeids-error

Conversation

@shubhamkumar9199
Copy link
Copy Markdown
Contributor

@shubhamkumar9199 shubhamkumar9199 commented Jan 1, 2026

This pr adjusts penalty-waiving behavior so penalties are waived via the dedicated waive endpoint before submitting repayment or reschedule requests.

WEB-536

Please make sure these boxes are checked before submitting your pull request - thanks!

  • If you have multiple commits please combine them into one commit by squashing them.

  • Read and understood the contribution guidelines at web-app/.github/CONTRIBUTING.md.

Summary by CodeRabbit

  • New Features

    • Penalty waivers can now be applied during loan rescheduling
    • Penalty waivers can now be applied during repayment transactions
    • Support for waiving multiple penalties simultaneously
  • Bug Fixes

    • Improved error handling: penalty waiver failures no longer block primary transaction completion

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 1, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'pre_merge_checks'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

The changes integrate penalty-waiving functionality into loan reschedule and repayment submission flows. A new waivePenalties method in PenaltyManagementService handles batch penalty waiving. Both components check for selected penalties and waive them before submission, proceeding regardless of waiver outcome.

Changes

Cohort / File(s) Change Summary
Loan Action Components
src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.ts, src/app/loans/loans-view/loan-account-actions/make-repayment/make-repayment.component.ts
Modified submission flow to waive penalties first (when enabled and penalties selected) before proceeding with reschedule/repayment. Introduced new private submitReschedule() and submitRepayment() helper methods to encapsulate submission logic. Penalty waiver failures do not block subsequent submission.
Penalty Management Service
src/app/loans/services/penalty-management.service.ts
Added public waivePenalties(loanId: string, penaltyIds: number[]) method that performs batch penalty waiving using forkJoin, with per-request error handling and early return for empty penalty lists.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Component as Reschedule/Repayment<br/>Component
    participant PenaltyService as PenaltyManagementService
    participant LoanService as LoanService
    participant Navigation

    User->>Component: Submit form
    alt Waive Penalties Enabled & Penalties Selected
        Component->>PenaltyService: waivePenalties(loanId, penaltyIds)
        activate PenaltyService
        PenaltyService->>LoanService: executeLoansAccountChargesCommand<br/>(waive) × N
        LoanService-->>PenaltyService: Results (success/error)
        PenaltyService-->>Component: Aggregated Results
        deactivate PenaltyService
        Note over Component: Continue regardless<br/>of waiver outcome
    end
    Component->>LoanService: submitRescheduleData/submitRepaymentData
    activate LoanService
    LoanService-->>Component: Success Response
    deactivate LoanService
    Component->>Navigation: Navigate to Loan View
    Navigation-->>User: Display Updated Loan
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • IOhacker

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding penalty waiving logic with proper chargeIds parameter handling before repayment/reschedule submission.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/app/loans/loans-view/loan-account-actions/make-repayment/make-repayment.component.ts (1)

330-343: Consider adding user feedback for penalty waiving operations.

The current implementation proceeds with repayment regardless of whether penalty waiving succeeds or fails. While this ensures the main operation isn't blocked, users receive no indication of the waiver outcome.

Consider:

  1. Adding a loading indicator during the async penalty waiving operation
  2. Displaying a success/error message to inform users of the waiver result
  3. Using a proper logging service instead of console.error for production environments
💡 Example with user feedback
if (this.waivePenalties && this.selectedPenalties.length > 0) {
  // Show loading indicator
  this.penaltyManagementService.waivePenalties(this.loanId, this.selectedPenalties).subscribe({
    next: (results) => {
      // Check if any penalties failed and show appropriate message
      const failedCount = results.filter(r => !r || !r.success).length;
      if (failedCount > 0) {
        // Show warning: "X penalties failed to waive, proceeding with repayment"
      } else {
        // Show success: "Penalties waived successfully"
      }
      this.submitRepayment(data);
    },
    error: (error) => {
      // Use proper logging service
      // Show error message to user
      this.submitRepayment(data);
    }
  });
} else {
  this.submitRepayment(data);
}
src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.ts (1)

130-143: Consider adding user feedback for penalty waiving operations.

Similar to the make-repayment component, this implementation proceeds with the reschedule regardless of penalty waiving success or failure. Users receive no indication of the waiver outcome.

Consider:

  1. Adding a loading indicator during the async penalty waiving operation
  2. Displaying a success/error message to inform users of the waiver result
  3. Using a proper logging service instead of console.error for production environments
💡 Example with user feedback
if (this.waivePenalties.value && this.selectedPenalties.length > 0) {
  // Show loading indicator
  this.penaltyManagementService.waivePenalties(this.loanId, this.selectedPenalties).subscribe({
    next: (results) => {
      // Check results and show appropriate message
      const failedCount = results.filter(r => !r || !r.success).length;
      if (failedCount > 0) {
        // Show warning: "X penalties failed to waive, proceeding with reschedule"
      } else {
        // Show success: "Penalties waived successfully"
      }
      this.submitReschedule(data);
    },
    error: (error) => {
      // Use proper logging service
      // Show error message to user
      this.submitReschedule(data);
    }
  });
} else {
  this.submitReschedule(data);
}
src/app/loans/services/penalty-management.service.ts (1)

198-215: Improve type safety and error handling for better observability.

The method has two areas worth improving:

  1. Type safety: Return type Observable<any[]> and error parameter any reduce type safety. Consider defining a result interface to properly represent success/failure for each penalty.

  2. Error observability: Using console.error and returning null silently swallows failures. Callers cannot distinguish which penalties succeeded vs. failed, making it difficult to provide meaningful user feedback.

The empty object {} parameter is correct and consistent with other 'waive' operations in the codebase.

🔎 Suggested improvements

Define a result type and improve error handling:

+interface WaivePenaltyResult {
+  chargeId: number;
+  success: boolean;
+  error?: any;
+}
+
-  waivePenalties(loanId: string, penaltyIds: number[]): Observable<any[]> {
+  waivePenalties(loanId: string, penaltyIds: number[]): Observable<WaivePenaltyResult[]> {
     if (!penaltyIds || penaltyIds.length === 0) {
       return of([]);
     }

     const waiveRequests = penaltyIds.map((chargeId: number) =>
       this.loanService.executeLoansAccountChargesCommand(loanId, 'waive', {}, chargeId).pipe(
-        catchError((error: any) => {
+        catchError((error) => {
           console.error(`Error waiving penalty ${chargeId}:`, error);
-          return of(null);
+          return of({ chargeId, success: false, error });
+        }),
+        map((response) => ({ chargeId, success: true, response }))
-        })
       )
     );

     return forkJoin(waiveRequests);
   }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b00c60e and a7738cc.

📒 Files selected for processing (3)
  • src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.ts
  • src/app/loans/loans-view/loan-account-actions/make-repayment/make-repayment.component.ts
  • src/app/loans/services/penalty-management.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
src/app/**

⚙️ CodeRabbit configuration file

src/app/**: For Angular code: verify component separation, trackBy on *ngFor,
strict type safety, and clean observable patterns.

Files:

  • src/app/loans/services/penalty-management.service.ts
  • src/app/loans/loans-view/loan-account-actions/make-repayment/make-repayment.component.ts
  • src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.ts
🧠 Learnings (1)
📚 Learning: 2025-12-09T14:24:31.429Z
Learnt from: alberto-art3ch
Repo: openMF/web-app PR: 2876
File: src/app/loans/loans-view/loan-account-actions/loan-reaging/loan-reaging.component.ts:91-94
Timestamp: 2025-12-09T14:24:31.429Z
Learning: In the LoanReagingComponent (src/app/loans/loans-view/loan-account-actions/loan-reaging/loan-reaging.component.ts), the transactionAmount field uses both Validators.min and Validators.max set to the same value (loanTransactionData.amount). This is intentional - it requires users to enter the exact amount as a confirmation/validation step before submitting the re-age operation.

Applied to files:

  • src/app/loans/loans-view/loan-account-actions/make-repayment/make-repayment.component.ts
🔇 Additional comments (2)
src/app/loans/loans-view/loan-account-actions/make-repayment/make-repayment.component.ts (1)

346-351: LGTM! Clean extraction of submission logic.

The helper method effectively reduces code duplication and provides a clear separation of concerns between penalty waiving and repayment submission.

src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.ts (1)

146-154: LGTM! Clean extraction of submission logic.

The helper method effectively reduces code duplication and provides a clear separation of concerns between penalty waiving and reschedule submission. The existing TODO comment is preserved for future navigation improvements.

Copy link
Copy Markdown
Contributor

@IOhacker IOhacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@IOhacker IOhacker merged commit c28f729 into openMF:dev Jan 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants