Skip to content

Commit

Permalink
feat: availability fetch
Browse files Browse the repository at this point in the history
adding a new function to fetch availabilities by a facility_id
  • Loading branch information
jxmoose committed Oct 6, 2024
1 parent 439b25b commit 933b92e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions api/supabase/queries/availability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import supabase from '../createClient';

export async function fetchAvailabilitiesByFacilityId(facility_id: string) {
try {
const { data, error } = await supabase
.from('availabilities')
.select('*')
.eq('facility_id', facility_id);
if (error) {
console.error('Error fetching availability by facility id:', error);
}
//Check if data array is not empty
if (data && data.length == 0) {
console.log(
'No availabilities found for this facility_id or facility_id is undefined',
);
return null; // Return null if no matching data found
}
console.log('Availability of facility', facility_id, ':', data);
} catch (error) {
console.error(`An unexpected error occurred:`, error);
return null; // Return null on unexpected error
}
}

0 comments on commit 933b92e

Please sign in to comment.