* Apply patch [skip ci] * Apply patch [skip ci] * Empty commit to trigger CI --------- Co-authored-by: open-swe-dev-andrinoid[bot] <open-swe-dev-andrinoid@users.noreply.github.com>
7.6 KiB
TODO - Lease Approval Workflow
Completed Components
1. Database Schema ✅
- Added approval workflow fields to
leasestable:approval_statusTEXT DEFAULT 'pending_approval'approval_requested_atBIGINTapproved_atBIGINTapproved_byTEXT REFERENCES users(id)rejection_reasonTEXT
- Created migration SQL file:
drizzle/0008_add_lease_approval_fields.sql - Updated database interfaces in
db/schema.ts
2. API Endpoints ✅
- Created
POST /api/lease/request-approval- Tenant initiates lease - Created
POST /api/lease/approve- Landlord approval - Created
POST /api/lease/reject- Landlord rejection - Created
GET /api/lease/pending-approvals- Landlord dashboard - Extended
leaseService.tswith approval functions:requestLeaseApproval()approveLease()rejectLease()getPendingApprovals()
3. Tenant Invitation Page ✅
- Updated
/tenant/invite/[invite_id].tsxto check lease status - Added status-based UI states:
- No lease: "Start Lease" button
- Pending: "Pending Landlord Approval"
- Approved: "Lease Approved - Continue"
- Rejected: "Lease Rejected" with contact info
- Added progress indicator showing approval steps
- Updated POST handler to call approval API
4. Landlord Service ✅
- Added
getPendingLeaseApprovals()function inlandlordService.ts
Incomplete / Needs Work
1. Notification Service ❌ (HIGH PRIORITY)
Status: File does not exist
Tasks:
- Create
services/notificationService.tsfor centralized notifications - Implement
sendLeaseApprovalRequest()function - Implement
sendLeaseApproved()function - Implement
sendLeaseRejected()function - Integrate with user
notification_preferences_jsonsystem - Follow
messageService.tspattern for E2E fixture support - Add E2E fixture functions in
services/e2eFixtures.ts
Integration Points:
- Call
sendLeaseApprovalRequest()inroutes/api/lease/request-approval.ts - Call
sendLeaseApproved()inroutes/api/lease/approve.ts - Call
sendLeaseRejected()inroutes/api/lease/reject.ts
2. Landlord Dashboard Updates ⚠️ (HIGH PRIORITY)
Status: Dashboard exists but missing "Pending Lease Approvals" section
Current State:
- Dashboard has "Pending Applications" section (for tenant applications)
- Dashboard does NOT have "Pending Lease Approvals" section
getPendingLeaseApprovals()function exists inlandlordService.tsbut is not used
Tasks:
- Add "Pending Lease Approvals" section to
routes/landlord/dashboard/index.tsx - Call
getPendingLeaseApprovals()fromlandlordService.ts - Display approval cards with property/tenant details
- Include approve/reject buttons calling
/api/lease/approveand/api/lease/reject - Use existing card styling pattern from dashboard
- Add navigation badge for pending approvals count
3. Dedicated Approvals Page ❌ (MEDIUM PRIORITY)
Status: Page does not exist
Tasks:
- Create
routes/landlord/approvals/index.tsx - Fetch pending approvals via
/api/lease/pending-approvals - Display detailed property and tenant information
- Provide approve/reject forms with optional rejection reason
- Follow Fresh page pattern from
routes/landlord/dashboard/index.tsx - Add navigation link in landlord menu
4. E2E Tests ❌ (MEDIUM PRIORITY)
Status: Test file exists but doesn't test approval workflow
Current State:
tests/e2e/lease-creation.spec.tsexists- Tests lease acceptance workflow but NOT approval workflow
Tasks:
- Create or update
tests/e2e/lease-approval.spec.ts - Test complete workflow: tenant requests, landlord views/approves, tenant sees status
- Use patterns from
tests/e2e/invite-tenant.spec.tsandhelpers.ts - Test approval status transitions (pending → approved/rejected)
- Test notification triggers (when notification service is implemented)
- Test error cases (unauthorized, invalid lease_id, etc.)
5. API Endpoint Validation ⚠️ (LOW PRIORITY)
Status: Endpoints exist but may need improvements
Tasks:
- Verify
routes/api/lease/request-approval.tshas proper error handling - Verify
routes/api/lease/approve.tshas proper error handling - Verify
routes/api/lease/reject.tshas proper error handling - Check
routes/api/lease/pending-approvals.tsreturns correct data structure - Add input validation and error messages
- Add notification calls when notification service is ready
6. Lease Finalization Verification ⚠️ (LOW PRIORITY)
Status: Basic implementation exists, needs verification
Tasks:
- Verify
inviteLease()inleaseService.tsproperly links to approved lease - Ensure tenant access rights are set up after approval
- Validate payment schedules are created on approval
- Test data integrity after approval workflow
- Verify lease status transitions correctly (draft → active)
Issues Discovered During Development
1. Missing Notification Integration
Issue: API endpoints for approve/reject don't send notifications Impact: Landlords and tenants won't receive email/dashboard notifications Fix Required: Implement notification service and integrate with endpoints
2. Dashboard Missing Pending Approvals Section
Issue: Landlord dashboard doesn't show pending lease approvals Impact: Landlords must navigate to a separate page to see approvals Fix Required: Add pending approvals section to dashboard
3. No Dedicated Approvals Page
Issue: /landlord/approvals route doesn't exist Impact: No centralized
location for landlords to manage approvals Fix Required: Create dedicated
approvals page
4. Incomplete E2E Test Coverage
Issue: No E2E tests for the complete approval workflow Impact: Difficult to verify end-to-end functionality Fix Required: Add comprehensive E2E tests
5. Variable Naming Consistency
Issue: Potential naming inconsistencies between services Impact: May cause confusion during maintenance Fix Required: Review and standardize variable names across files
Verification Steps
After completing each component, run:
deno check <modified_ts_file>
deno fmt <modified_ts_file>
deno lint <modified_ts_file>
Note: deno check only works on TypeScript files (.ts), not Markdown files
(.md).
Workflow Summary
- Tenant clicks "Start Lease" → Creates lease with
approval_status: 'pending_approval' - Landlord receives notification → Dashboard shows pending approval
- Landlord reviews and approves/rejects → Updates lease status
- System finalizes lease → Links records, sets up payments, grants access
Files to Create
services/notificationService.ts- New notification serviceroutes/landlord/approvals/index.tsx- Dedicated approvals pagetests/e2e/lease-approval.spec.ts- E2E tests for approval workflow
Files to Modify
routes/landlord/dashboard/index.tsx- Add pending approvals sectionroutes/api/lease/approve.ts- Add notification callroutes/api/lease/reject.ts- Add notification callroutes/api/lease/request-approval.ts- Add notification callservices/e2eFixtures.ts- Add notification E2E fixtures
Success Criteria
- All lease activations require landlord approval
- Tenants see clear approval status
- Landlords can easily review and approve/reject
- Notifications are sent reliably
- Lease finalization works correctly
- All tests pass
- Dashboard shows pending approvals
- Dedicated approvals page exists