-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding a new function to fetch availabilities by a facility_id
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |