Dont add anything new to the schema
📋 Description
Create endpoints for admins to approve or reject adoption requests. When approved, the pet status should update and (optionally) trigger escrow creation. When rejected, the pet returns to available status.
🎯 Context
After users submit adoption requests (#12) and admins can view them (#13), admins need the ability to make decisions. Approval moves the adoption forward (potentially creating blockchain escrow), while rejection frees the pet for other adopters.
📝 What You'll Build
Two Admin Endpoints
1. PATCH /adoptions/:id/approve - Approve a request
- Changes adoption status: PENDING → APPROVED
- Changes pet status: PENDING → AVAILABLE (or keeps PENDING for escrow)
- Optional: Triggers escrow creation (Phase 2)
- Returns updated adoption
2. PATCH /adoptions/:id/reject - Reject a request
- Changes adoption status: PENDING → REJECTED
- Changes pet status: PENDING → AVAILABLE
- Optional: Accepts rejection reason
- Returns updated adoption
What Happens on Approval
1. Validate adoption exists and is PENDING
2. Update adoption status to APPROVED
3. Update approvedAt timestamp
4. Future: Trigger escrow creation
5. Future: Send notification to adopter
6. Return updated adoption
What Happens on Rejection
1. Validate adoption exists and is PENDING
2. Update adoption status to REJECTED
3. Update pet status to AVAILABLE (free for others)
4. Optional: Store rejection reason/notes
5. Future: Send notification to adopter
6. Return updated adoption
🔧 Implementation Checklist
Files to Create/Modify
What to Build
Approve Method:
- Accept adoptionId and adminUserId
- Verify adoption exists and status is PENDING
- Update adoption status to APPROVED
- Set approvedAt timestamp to now
- Return updated adoption with pet and user data
Reject Method:
- Accept adoptionId, adminUserId, and optional reason
- Verify adoption exists and status is PENDING
- Update adoption status to REJECTED
- Update pet status back to AVAILABLE
- Store rejection reason in notes field
- Return updated adoption
Validation:
- Only PENDING adoptions can be approved/rejected
- Only ADMIN role can perform these actions
- Adoption must exist (404 if not found)
- Pet must exist and be linked to adoption
Authorization:
- Both endpoints require ADMIN role
- Apply JwtAuthGuard + RolesGuard
- Use @roles('ADMIN') decorator
✅ Acceptance Criteria
🧪 How to Test
Setup:
- Create ADMIN user
- Create SHELTER user
- Create regular USER
- Shelter creates a pet
- User submits adoption request (status: PENDING, pet: PENDING)
Test Approval Flow:
-
Admin approves adoption:
- Login as ADMIN
- PATCH /adoptions/123/approve
- Response: 200 OK ✅
- Adoption status: APPROVED
- approvedAt: Current timestamp
- Pet status: PENDING (ready for escrow)
-
Non-admin tries to approve:
- Login as regular USER or SHELTER
- PATCH /adoptions/123/approve
- Response: 403 Forbidden ❌
-
Approve already approved:
- PATCH /adoptions/123/approve (already APPROVED)
- Response: 400 Bad Request ❌
- Error: "Adoption is not pending"
-
Approve non-existent:
- PATCH /adoptions/999/approve
- Response: 404 Not Found ❌
Test Rejection Flow:
-
Admin rejects adoption:
- Create new PENDING adoption
- Login as ADMIN
- PATCH /adoptions/456/reject
- Body:
{ "reason": "Incomplete documentation" }
- Response: 200 OK ✅
- Adoption status: REJECTED
- Pet status: AVAILABLE (freed for others)
- notes: "Incomplete documentation"
-
Reject without reason:
- PATCH /adoptions/456/reject
- Body:
{} (empty)
- Should still work ✅
-
Non-admin tries to reject:
- Login as regular USER
- PATCH /adoptions/456/reject
- Response: 403 Forbidden ❌
Edge Cases:
- Approve COMPLETED adoption → 400 Bad Request
- Reject REJECTED adoption → 400 Bad Request
- Approve CANCELLED adoption → 400 Bad Request
Suggested Approach:
- Create approve endpoint in controller (ADMIN only)
- Create reject endpoint in controller (ADMIN only)
- Implement approve logic in service
- Implement reject logic in service
- Add status validation for both
- Test with Postman/curl
- Add unit tests
- Update Swagger docs
Transaction Tip:
Use Prisma transactions for reject (updates adoption + pet) to ensure data consistency.
Approve Flow
Adoption: PENDING → APPROVED
Pet: PENDING → PENDING (awaiting escrow)
Reject Flow
Adoption: PENDING → REJECTED
Pet: PENDING → AVAILABLE (freed)
Dont add anything new to the schema
📋 Description
Create endpoints for admins to approve or reject adoption requests. When approved, the pet status should update and (optionally) trigger escrow creation. When rejected, the pet returns to available status.
🎯 Context
After users submit adoption requests (#12) and admins can view them (#13), admins need the ability to make decisions. Approval moves the adoption forward (potentially creating blockchain escrow), while rejection frees the pet for other adopters.
📝 What You'll Build
Two Admin Endpoints
1. PATCH /adoptions/:id/approve - Approve a request
2. PATCH /adoptions/:id/reject - Reject a request
What Happens on Approval
What Happens on Rejection
🔧 Implementation Checklist
Files to Create/Modify
src/adoption/adoption.controller.ts- Add approve/reject endpointssrc/adoption/adoption.service.ts- Add approve/reject methodssrc/adoption/dto/reject-adoption.dto.ts- Optional rejection reason DTOsrc/pets/pets.service.ts- May need to update pet statusWhat to Build
Approve Method:
Reject Method:
Validation:
Authorization:
✅ Acceptance Criteria
🧪 How to Test
Setup:
Test Approval Flow:
Admin approves adoption:
Non-admin tries to approve:
Approve already approved:
Approve non-existent:
Test Rejection Flow:
Admin rejects adoption:
{ "reason": "Incomplete documentation" }Reject without reason:
{}(empty)Non-admin tries to reject:
Edge Cases:
Suggested Approach:
Transaction Tip:
Use Prisma transactions for reject (updates adoption + pet) to ensure data consistency.
Approve Flow
Reject Flow