Skip to content

Implement custody return and violation lifecycle#97

Open
kingjosmel wants to merge 2 commits intoamina69:mainfrom
kingjosmel:feature/custody-return-lifecycle
Open

Implement custody return and violation lifecycle#97
kingjosmel wants to merge 2 commits intoamina69:mainfrom
kingjosmel:feature/custody-return-lifecycle

Conversation

@kingjosmel
Copy link
Copy Markdown

PR: Implement Custody Return and Violation Lifecycle

close #63

Overview

This PR implements the complete custody return lifecycle, including escrow resolution and trust score updates. It adds methods to handle successful custody returns and violations with proper event logging.

Features

  • Return Custody: returnCustody(custodyId) - End custody successfully

    • Validates custody is ACTIVE
    • Updates status to RETURNED
    • Releases escrow if exists
    • Increases trust score by +5
    • Emits CUSTODY_RETURNED event
  • Violation Custody: violationCustody(custodyId) - Report custody violation

    • Validates custody is ACTIVE
    • Updates status to VIOLATION
    • Refunds escrow if exists
    • Penalizes trust score by -15
    • Emits CUSTODY_VIOLATION event
  • Trust Score Management: updateTrustScore(userId, delta) - Update user trust scores

    • Maintains 0-100 range
    • Emits TRUST_SCORE_UPDATED events
  • Escrow Refund: refundEscrow(escrowId) - Refund escrow on violations

    • Updates status to REFUNDED
    • Emits ESCROW_REFUNDED event
  • API Endpoints:

    • POST /custody/:id/return - Return custody agreement
    • POST /custody/:id/violation - Mark custody as violation

Acceptance Criteria

✅ Successful custody releases escrow
✅ Violation refunds escrow
✅ Trust score updated correctly
✅ EventLog entries created
✅ Pet availability updated (computed dynamically)

Notes

  • All database operations use transactions for atomicity
  • Trust score is bounded between 0-100
  • Full TypeScript compilation success

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 26, 2026

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

@amina69
Copy link
Copy Markdown
Owner

amina69 commented Mar 26, 2026

@kingjosmel test failed

@kingjosmel
Copy link
Copy Markdown
Author

@amina69 i've fix the test

@amina69
Copy link
Copy Markdown
Owner

amina69 commented Mar 31, 2026

@kingjosmel kindly fixed this small conflict

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.

Custody Return Flow

2 participants