Skip to content

Complete the Notifications Flow (wire all lifecycle events) #89

Description

@ManuelJG1999

Complete the Notifications Flow (wire all lifecycle events)

Depends on:

Task Description

The notifications module is partially wired. NotificationsService already has methods for created, funded, completed, evidence submitted, milestone approved, dispute opened, and dispute resolved. However, NotificationsListener only subscribes to 3 events (agreement.created, agreement.funded, agreement.completed), so several notification methods are effectively dead code — nothing triggers them end-to-end. This issue closes the gaps so every lifecycle event actually reaches the user.

Background / Current State

Verified against main:

  1. Dispute notifications not wired: disputes.service.ts emits DISPUTE_OPENED and DISPUTE_RESOLVED, and the service has notifyDisputeOpened / notifyDisputeResolved, but NotificationsListener has no handlers for them.
  2. Evidence & milestone events never emitted: notifyEvidenceSubmitted / notifyMilestoneApproved (and handleEvidenceSubmitted / handleMilestoneApproved) exist, but no code emits evidence_submitted or milestone_approved.
  3. Fragmented event constants: AGREEMENT_EVENTS only defines CREATED/FUNDED/COMPLETED, while disputes use separate DISPUTE_OPENED/DISPUTE_RESOLVED constants in another file.

Deliverable

A fully wired event → listener → email flow covering all agreement lifecycle events.

Requirements

  • Wire dispute notifications: add @OnEvent handlers for DISPUTE_OPENED and DISPUTE_RESOLVED.
  • Emit evidence/milestone events: emit evidence_submitted and milestone_approved from the milestone update path in agreements.service.ts.
  • Consolidate event constants: merge into one events constants source used by both agreements and disputes.

Validation System

  • Opening a dispute sends the dispute-opened email; resolving sends dispute-resolved.
  • Approving a milestone and submitting evidence each trigger their emails.
  • Created/funded/completed continue to work (including the webhook-driven funded/completed path in webhooks.service.ts).
  • Listener failures are logged but do not crash the request (keep the existing try/catch pattern).

Technical Requirements

  • EventEmitterModule is already registered — reuse it; no new infra.
  • Extend NotificationsListener with the missing @OnEvent handlers.
  • Emit missing events from the correct service methods (not from controllers).
  • Update/extend notifications.listener.spec.ts to cover the new handlers.

Additional Notes

Scope is wiring, not new templates — the email templates and service methods already exist. This is why emails "aren't arriving" for disputes/milestones today: the events are never delivered to the service.

Testing (required)

  • Unit test: each new @OnEvent handler invokes the correct notification method.
  • Integration test: dispute open/resolve, milestone approved, and evidence submitted each produce their email end-to-end.
  • Regression test: created/funded/completed (including the webhook path) still fire.
  • Resilience test: a listener failure is logged and does not crash the request.

Proof of Completion (required)

  • Link the merged PR.
  • Paste passing test output (including the extended notifications.listener.spec.ts).
  • Attach evidence (logs/screenshots or Resend dashboard) showing dispute and milestone/evidence emails actually sent.
  • Confirm (link/diff) the consolidated event-constants source.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions