fix(frontend): robust error handling in fetchers and fix UUID casting
This commit is contained in:
@@ -225,7 +225,7 @@ export async function fetchGeneratedArticleBySlug(
|
|||||||
filter: {
|
filter: {
|
||||||
_and: [
|
_and: [
|
||||||
{ slug: { _eq: slug } },
|
{ slug: { _eq: slug } },
|
||||||
{ site_id: { _eq: Number(siteId) } },
|
{ site_id: { _eq: siteId } },
|
||||||
{ is_published: { _eq: true } }
|
{ is_published: { _eq: true } }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -270,31 +270,46 @@ export async function fetchCampaigns(siteId?: string) {
|
|||||||
* Fetch locations (states, counties, cities)
|
* Fetch locations (states, counties, cities)
|
||||||
*/
|
*/
|
||||||
export async function fetchStates() {
|
export async function fetchStates() {
|
||||||
return directus.request(
|
try {
|
||||||
readItems('locations_states', {
|
return await directus.request(
|
||||||
sort: ['name'],
|
readItems('locations_states', {
|
||||||
fields: ['*']
|
sort: ['name'],
|
||||||
})
|
fields: ['*']
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching states:', err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchCountiesByState(stateId: string) {
|
export async function fetchCountiesByState(stateId: string) {
|
||||||
return directus.request(
|
try {
|
||||||
readItems('locations_counties', {
|
return await directus.request(
|
||||||
filter: { state: { _eq: stateId } },
|
readItems('locations_counties', {
|
||||||
sort: ['name'],
|
filter: { state: { _eq: stateId } },
|
||||||
fields: ['*']
|
sort: ['name'],
|
||||||
})
|
fields: ['*']
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching counties:', err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchCitiesByCounty(countyId: string, limit = 50) {
|
export async function fetchCitiesByCounty(countyId: string, limit = 50) {
|
||||||
return directus.request(
|
try {
|
||||||
readItems('locations_cities', {
|
return await directus.request(
|
||||||
filter: { county: { _eq: countyId } },
|
readItems('locations_cities', {
|
||||||
sort: ['-population'],
|
filter: { county: { _eq: countyId } },
|
||||||
limit,
|
sort: ['-population'],
|
||||||
fields: ['*']
|
limit,
|
||||||
})
|
fields: ['*']
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching cities:', err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user