Skip to content

Pet Availability Resolver (Computed State) #61

@amina69

Description

@amina69

Implement Computed Pet Availability Resolver

Labels:
backend architecture domain-logic

🎯 Goal

Remove reliance on stored Petstatus in the schema or any other place in the code because it should be computed.

Pet availability must be computed dynamically from:

Active adoption records

Active custody records

Ownership data

🧠 Why This Matters

We avoid conflicting state such as:

Pet marked AVAILABLE but adoption COMPLETED

Pet marked ADOPTED but escrow not released

Computed state guarantees consistency.

🧮 Availability Rules
1️⃣ If Adoption.status = COMPLETED

→ ADOPTED

2️⃣ If Custody.status = ACTIVE

→ IN_CUSTODY

3️⃣ If Adoption.status in (REQUESTED, PENDING_REVIEW, APPROVED, ESCROW_FUNDED)

→ PENDING

4️⃣ Otherwise

→ AVAILABLE

🏗 Implementation Plan

Create:

PetAvailabilityService

Method:

async resolve(petId: string): Promise

Service should:

Query latest adoption for pet

Query active custody

Apply priority rules

Return computed state

⚠️ Priority Order

Adopted overrides custody.
Custody overrides pending.
Pending overrides available.

🔒 Acceptance Criteria

Pet model contains NO status column

Availability is derived only

Unit tests for all scenarios

Used in all Pet queries (list + single)

EventLog created when state changes due to adoption/custody updates

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions