Skip to content

Implement open dispute API for delivery issues - #79

Merged
Tybravo merged 2 commits into
SwiftChainn:mainfrom
Elizabethxxx:feat/open-dispute-api
Jul 28, 2026
Merged

Implement open dispute API for delivery issues#79
Tybravo merged 2 commits into
SwiftChainn:mainfrom
Elizabethxxx:feat/open-dispute-api

Conversation

@Elizabethxxx

Copy link
Copy Markdown
Contributor

closes #44

Summary

Allows a delivery's customer or driver to open a dispute before any corresponding on-chain dispute workflow is executed.

  • New Dispute model (src/models/Dispute.ts) with reason (enum), description, optional evidenceUrls, and lifecycle status (open / under_review / resolved / rejected)
  • disputeService.createDispute (src/services/disputeService.ts) enforces:
    • the referenced delivery exists
    • the delivery is currently active (assigned or in_progress) — pending, completed, and cancelled deliveries cannot be disputed
    • only the delivery's customer or assigned driver may open a dispute
    • a delivery cannot have more than one unresolved dispute open at a time
    • all data is read from and written to MongoDB, no inline mocks or hardcoded values
  • The current Soroban ledger sequence is stamped onto the dispute (via the existing sorobanService.getLatestLedger()) for an audit trail, non-blocking if the RPC call fails
  • POST /api/v1/disputes, protected by authenticate, request body validated with a zod schema (src/validators/disputeValidator.ts)

Architecture

Follows the existing layered pattern: disputeRoutes.ts -> validate(createDisputeSchema) -> disputeController.ts -> disputeService.ts -> Dispute model.

Test plan

  • npx jest tests/dispute.test.ts — 13/13 passing, covering the success path (customer and driver), validation errors, missing auth, non-participant rejection, delivery-not-found, duplicate-open-dispute conflict, and non-active-delivery business rule violations
  • npx tsc --noEmit — introduces no new TypeScript errors (pre-existing unrelated errors in deliveryController.ts are untouched by this change)
  • npx eslint on all added/changed files — no errors
  • Full npx jest suite — same 4 pre-existing failing suites as on main prior to this branch; no regressions introduced

Allows a delivery's customer or driver to open a dispute before any
on-chain dispute workflow runs.

- New Dispute model tracking reason, description, evidence, and
  lifecycle status
- disputeService validates the delivery exists and is in an active
  state (assigned or in progress), restricts the action to delivery
  participants, and prevents duplicate open disputes on the same
  delivery
- POST /api/v1/disputes, authenticated, request body validated with
  zod
- Stamps the current Soroban ledger sequence onto each dispute via the
  existing sorobanService for an audit trail
- Tests cover the success path plus validation, auth, not-found,
  conflict, and business-rule failure cases
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@Elizabethxxx 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

@Tybravo
Tybravo merged commit a497e5f into SwiftChainn:main Jul 28, 2026
1 check failed
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.

Backend: Implement Open Dispute API allowing users to flag delivery issues

2 participants