trip) adding support for lodgings
This commit is contained in:
@@ -99,9 +99,43 @@ export function getPlanCountForTrip(tripId: string, userId: string): number {
|
||||
return row?.count ?? 0;
|
||||
}
|
||||
|
||||
export function searchCities(query: string): City[] {
|
||||
export interface Country {
|
||||
name: string;
|
||||
country_code: string;
|
||||
}
|
||||
|
||||
export function getCountries(query?: string): Country[] {
|
||||
if (!query?.trim()) {
|
||||
return db.all<Country>(
|
||||
`SELECT DISTINCT country as name, country_code FROM cities ORDER BY country`
|
||||
);
|
||||
}
|
||||
const pattern = `%${query.trim()}%`;
|
||||
return db.all<Country>(
|
||||
`SELECT DISTINCT country as name, country_code
|
||||
FROM cities
|
||||
WHERE country LIKE ? COLLATE NOCASE
|
||||
ORDER BY country
|
||||
LIMIT 50`,
|
||||
[pattern]
|
||||
);
|
||||
}
|
||||
|
||||
export function searchCities(query: string, countryCode?: string): City[] {
|
||||
if (!query.trim()) return [];
|
||||
const pattern = `%${query.trim()}%`;
|
||||
if (countryCode?.trim()) {
|
||||
return db.all<City>(
|
||||
`SELECT id, name, country, country_code, population
|
||||
FROM cities
|
||||
WHERE name LIKE ? COLLATE NOCASE AND country_code = ?
|
||||
ORDER BY
|
||||
CASE WHEN name LIKE ? COLLATE NOCASE THEN 0 ELSE 1 END,
|
||||
population DESC NULLS LAST
|
||||
LIMIT 10`,
|
||||
[pattern, countryCode.trim().toUpperCase(), `${query.trim()}%`]
|
||||
);
|
||||
}
|
||||
return db.all<City>(
|
||||
`SELECT id, name, country, country_code, population
|
||||
FROM cities
|
||||
|
||||
Reference in New Issue
Block a user