Skip to content

fix(#163,#162): list_credits status filter defaults to Active + retire event ordering#174

Open
akindoyinabraham0-collab wants to merge 1 commit into
legend-esc:mainfrom
akindoyinabraham0-collab:fix/163-list-credits-status-filter-162-retire-event-ordering
Open

fix(#163,#162): list_credits status filter defaults to Active + retire event ordering#174
akindoyinabraham0-collab wants to merge 1 commit into
legend-esc:mainfrom
akindoyinabraham0-collab:fix/163-list-credits-status-filter-162-retire-event-ordering

Conversation

@akindoyinabraham0-collab
Copy link
Copy Markdown

Closes #163
Closes #162

Summary

Two bugs fixed in a single branch.


Fix #163list_credits defaults to Active-only

Root cause: listCredits in credits.service.ts built its candidate list from a hardcoded empty array, so every filter — including the status filter — was dead code. The endpoint always returned an empty result set.

Changes:

  • credit.repository.ts — added findByStatus(status, page, limit) to ICreditRepository and InMemoryCreditRepository.
  • credits.service.tslistCredits now reads from creditRepo.findByStatus(), defaulting to CreditStatus.Active when no status query param is supplied. Secondary filters (methodology, geography, vintageYear, tonnes range) are applied in-memory on top.
  • credit.repository.spec.ts — six new tests covering every CreditStatus value (Active, Retired, Flagged, Pending), the empty-result case, and pagination.

Fix #162retire emits CreditRetired only after record is persisted

Root cause: No explicit application-level event emission existed, but the method needed a clear enforced ordering guarantee so any future listener could never observe a CreditRetired event without a corresponding record in storage.

Changes:

  • retirement.service.ts — introduced IEventEmitter interface and EVENT_EMITTER injection token. retire() now explicitly emits CreditRetired after retirementRepo.save() resolves. If the save throws, the event is never emitted. Ordering guarantee documented in JSDoc.
  • retirement.module.ts — provides a Node.js EventEmitter instance bound to EVENT_EMITTER (no new npm dependency).
  • retirement.service.spec.ts — new test file with six tests: save-before-emit order, record exists at emit time, no event on write failure, exactly one event per call, correct payload, record retrievable after retire.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@akindoyinabraham0-collab Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Fix: list_credits includes Retired and Flagged credits with no opt-out Fix: retire emits CreditRetired event before writing retirement record

1 participant