Files
property-match/src/hooks/useMatches.ts
T
Benjamin Sutter 5ef8b9d69d feat(services): F005 – complete service layer
New domain types:
- shortlist.ts: Shortlist, ShortlistItem, CreateShortlistInput
- review.ts: ReviewQueueItem, ReviewPriority, ReviewQueueStatus

New mock data:
- shortlists.ts: 2 sample shortlists
- reviewQueue.ts: 3 pending review items

New providers (interface + mockup):
- IShortlistProvider / MockupShortlistProvider (with 150ms latency)
- IReviewProvider / MockupReviewProvider (priority-sorted, with latency)
- IDashboardProvider / MockupDashboardProvider (computed from all mock data)

New services:
- reviewService: getQueue, approve, reject, assign
- shortlistService: CRUD + addItem/removeItem
- authService: wraps sessionStore, swappable for real auth
- dashboardService: getStats(organizationId?)

Enhancements:
- types.ts: typed ServiceErrorCode + ServiceError, Pagination alias
- aiService.ts: openRouterAIService stub (throws ai_generation_failed)
- lib/mockUtils.ts: mockDelay(ms) utility

New hooks:
- useUnifiedResults(needId?): joins matches+properties+signals → UnifiedMatchResult[]
- useReviewQueue: + useApproveReviewItem + useRejectReviewItem
- useMatchDetail, usePropertyDetail, useNeedProfiles aliases

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:12:06 +02:00

53 lines
1.4 KiB
TypeScript

import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { matchService } from '../services/matchService'
import { STALE_MATCHES } from '../lib/constants'
export function useMatches() {
return useQuery({
queryKey: ['matches'],
queryFn: () => matchService.getAll(),
staleTime: STALE_MATCHES,
select: (res) => res.data ?? [],
})
}
export function useMatchesByNeed(needId: string) {
return useQuery({
queryKey: ['matches', 'need', needId],
queryFn: () => matchService.getByNeed(needId),
staleTime: STALE_MATCHES,
enabled: Boolean(needId),
select: (res) => res.data ?? [],
})
}
export function useMatchesByProperty(propertyId: string) {
return useQuery({
queryKey: ['matches', 'property', propertyId],
queryFn: () => matchService.getByProperty(propertyId),
staleTime: STALE_MATCHES,
enabled: Boolean(propertyId),
select: (res) => res.data ?? [],
})
}
export function useApproveMatch() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (matchId: string) => matchService.approve(matchId, 'current-user'),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['matches'] })
},
})
}
export function useMatchDetail(id: string) {
return useQuery({
queryKey: ['match', id],
queryFn: () => matchService.getById(id),
staleTime: STALE_MATCHES,
enabled: Boolean(id),
select: (res) => res.data ?? null,
})
}