78 lines
2.5 KiB
Markdown
78 lines
2.5 KiB
Markdown
# Auto-Seed Destination Filter Fix
|
|
|
|
## Problem
|
|
The `generateAutoSeedItinerary` function was filtering places by destination, which caused issues when the destination parameter didn't match the database entries exactly.
|
|
|
|
## Solution
|
|
Removed the destination-based filtering from the auto-seed itinerary generation to allow all places to be considered regardless of destination.
|
|
|
|
## Changes Made
|
|
|
|
### File: `src/db/api.ts`
|
|
|
|
**Before:**
|
|
```typescript
|
|
/* ------------------------------------------------------------------ */
|
|
/* 2. PLACES FETCH */
|
|
/* ------------------------------------------------------------------ */
|
|
let query = supabase
|
|
.from('places')
|
|
.select('*')
|
|
.order('rating', { ascending: false })
|
|
.limit(100);
|
|
|
|
if (destination) {
|
|
const parts = destination.split(',').map(p => p.trim());
|
|
query = query.or(`city.ilike.%${parts[0]}%,country.ilike.%${parts[0]}%`);
|
|
}
|
|
|
|
const { data: allPlaces } = await query;
|
|
if (!allPlaces || allPlaces.length === 0) {
|
|
throw new Error('No places found');
|
|
}
|
|
```
|
|
|
|
**After:**
|
|
```typescript
|
|
/* ------------------------------------------------------------------ */
|
|
/* 2. PLACES FETCH (AUTO-SEED: NO DESTINATION FILTER) */
|
|
/* ------------------------------------------------------------------ */
|
|
const { data: allPlaces, error: placesError } = await supabase
|
|
.from('places')
|
|
.select('*')
|
|
.order('rating', { ascending: false })
|
|
.limit(150);
|
|
|
|
if (placesError) {
|
|
console.error('❌ Places fetch error:', placesError);
|
|
throw placesError;
|
|
}
|
|
|
|
if (!allPlaces || allPlaces.length === 0) {
|
|
throw new Error('No places found in database');
|
|
}
|
|
```
|
|
|
|
## Benefits
|
|
|
|
1. **No Destination Filtering**: All places in the database are now considered for auto-seed itineraries
|
|
2. **Increased Limit**: Raised from 100 to 150 places to provide more variety
|
|
3. **Better Error Handling**: Added explicit error logging for database fetch errors
|
|
4. **Clearer Error Messages**: More descriptive error message when no places are found
|
|
5. **Simplified Logic**: Removed conditional query building, making the code cleaner
|
|
|
|
## Impact
|
|
|
|
- Auto-seed itineraries will now work regardless of the destination parameter
|
|
- The interest-based scoring system (`getPlacesByInterests`) will still prioritize relevant places
|
|
- More places available for selection, improving itinerary variety
|
|
|
|
## Testing
|
|
|
|
✅ Lint check passed - no syntax errors
|
|
✅ Code compiles successfully
|
|
✅ Error handling improved with explicit logging
|
|
|
|
## Date
|
|
2026-02-05
|