@@ -133,21 +133,30 @@ class ApiClient {
|
||||
});
|
||||
|
||||
try {
|
||||
// Validate auth state before making request
|
||||
if (!this.authFetch) {
|
||||
throw new Error('Auth fetch not available');
|
||||
}
|
||||
|
||||
if (action === 'status' && (!data.facilityId || !data.statusComment)) {
|
||||
throw new Error('Missing required data for status update');
|
||||
}
|
||||
|
||||
// Use authenticated fetch for all facility requests
|
||||
const response = await this.authFetch('/facilitycontroller.php', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
requireAuth: true // Explicitly require authentication
|
||||
requireAuth: true
|
||||
});
|
||||
|
||||
// Parse the response
|
||||
const jsonData = await response.json();
|
||||
|
||||
// Check if response is ok
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
throw new Error(`HTTP error! status: ${response.status}, message: ${jsonData.error || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
// Parse the JSON response
|
||||
const jsonData = await response.json();
|
||||
console.log('Facility API response:', { action, data: jsonData });
|
||||
return jsonData;
|
||||
} catch (error) {
|
||||
console.error('Facility API error:', error);
|
||||
@@ -242,7 +251,11 @@ class ApiClient {
|
||||
* @returns {Promise<Object>} The response data
|
||||
*/
|
||||
async updateFacilityStatus(statusId, editStatus, facilityId) {
|
||||
return this.facility('editStatus', { statusId, editStatus, facilityId });
|
||||
return this.facility('editStatus', {
|
||||
statusId: statusId,
|
||||
statusComment: editStatus,
|
||||
facilityId: facilityId
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,7 +272,7 @@ class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize API client
|
||||
// initialise API client
|
||||
const api = new ApiClient();
|
||||
|
||||
// Export API client
|
||||
|
Reference in New Issue
Block a user