-
Notifications
You must be signed in to change notification settings - Fork 24
Custody Lifecycle State Machine #60
Description
Implement Custody Lifecycle State Machine
Labels:
backend domain-logic state-machine
🎯 Goal
Enforce valid lifecycle transitions for Custody.status.
Custody must not be arbitrarily reopened or reversed.
🧠 Context
Custody represents temporary responsibility over a pet (rehoming, temporary care, etc).
It affects:
Pet availability
Trust scoring
Movement history
Invalid transitions could corrupt the pet movement timeline.
📊 Valid Custody Flow
ACTIVE
↓
RETURNED
Alternative flows
ACTIVE → CANCELLED
ACTIVE → VIOLATION
❌ Invalid Transitions
RETURNED → ACTIVE
CANCELLED → ACTIVE
VIOLATION → ACTIVE
RETURNED → CANCELLED
All terminal states are immutable.
🏗 Implementation Plan
1️⃣ Create CustodyStateMachine service
class CustodyStateMachine {
canTransition(from: CustodyStatus, to: CustodyStatus): boolean
}
2️⃣ Define transition map
const transitions = {
ACTIVE: ['RETURNED', 'CANCELLED', 'VIOLATION'],
RETURNED: [],
CANCELLED: [],
VIOLATION: []
}
3️⃣ Enforce validation before update
🔒 Acceptance Criteria
Invalid transitions blocked
Terminal states immutable
Timeline events logged
Trust score updated on VIOLATION
Unit tests added