diff --git a/cannaiq/src/lib/api.ts b/cannaiq/src/lib/api.ts index a19afe58..8082ae51 100755 --- a/cannaiq/src/lib/api.ts +++ b/cannaiq/src/lib/api.ts @@ -35,8 +35,21 @@ class ApiClient { } // Generic HTTP methods (axios-style interface) - async get(endpoint: string): Promise<{ data: T }> { - const data = await this.request(endpoint); + async get(endpoint: string, config?: { params?: Record }): Promise<{ data: T }> { + let url = endpoint; + if (config?.params) { + const searchParams = new URLSearchParams(); + Object.entries(config.params).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + searchParams.append(key, String(value)); + } + }); + const queryString = searchParams.toString(); + if (queryString) { + url += (url.includes('?') ? '&' : '?') + queryString; + } + } + const data = await this.request(url); return { data }; } @@ -48,6 +61,14 @@ class ApiClient { return { data }; } + async put(endpoint: string, body?: any): Promise<{ data: T }> { + const data = await this.request(endpoint, { + method: 'PUT', + body: body ? JSON.stringify(body) : undefined, + }); + return { data }; + } + // Auth async login(email: string, password: string) { return this.request<{ token: string; user: any }>('/api/auth/login', { diff --git a/cannaiq/src/pages/DiscoveryLocations.tsx b/cannaiq/src/pages/DiscoveryLocations.tsx index 89e92c0d..3fe489e9 100644 --- a/cannaiq/src/pages/DiscoveryLocations.tsx +++ b/cannaiq/src/pages/DiscoveryLocations.tsx @@ -69,10 +69,25 @@ export function DiscoveryLocations() { try { setLoading(true); const [locsData, statsData] = await Promise.all([ - api.getDiscoveryLocations({ state: stateFilter, status: statusFilter, limit: 500 }), + api.getDiscoveryLocations({ stateCode: stateFilter || undefined, status: statusFilter || undefined, limit: 500 }), api.getDiscoveryStats(), ]); - setLocations(locsData.locations || []); + // Map the API response to match our interface + const mappedLocations = (locsData.locations || []).map((loc: any) => ({ + id: loc.id, + platform: loc.platform, + platform_location_id: loc.platformLocationId || loc.platform_location_id, + name: loc.name, + city: loc.city, + state_code: loc.stateCode || loc.state_code, + status: loc.status, + platform_menu_url: loc.platformMenuUrl || loc.platform_menu_url, + dispensary_id: loc.dispensaryId ?? loc.dispensary_id ?? null, + first_seen_at: loc.firstSeenAt || loc.first_seen_at, + last_seen_at: loc.lastSeenAt || loc.last_seen_at, + verified_at: loc.verifiedAt || loc.verified_at, + })); + setLocations(mappedLocations); setStats(statsData); } catch (error) { console.error('Failed to load discovery data:', error); @@ -114,7 +129,7 @@ export function DiscoveryLocations() {

Discovery Locations

- Dutchie stores discovered via API - {stats?.total || 0} total + Dutchie stores discovered via API - {stats?.locations?.total || 0} total