mirror of
https://github.com/ferdzo/iotDashboard.git
synced 2026-04-05 17:16:26 +00:00
Introduced air quality and weather, onboarding for mobile devices with qr code and otp. Cascade on delete of device with telemtry.
This commit is contained in:
@@ -17,7 +17,24 @@ interface PaginatedResponse<T> {
|
||||
|
||||
// Device API
|
||||
export const devicesApi = {
|
||||
getAll: () => apiClient.get<PaginatedResponse<Device>>('/devices/'),
|
||||
getAll: async () => {
|
||||
const response = await apiClient.get<Device[] | PaginatedResponse<Device>>('/devices/');
|
||||
// Handle both paginated and non-paginated responses
|
||||
if (Array.isArray(response.data)) {
|
||||
// Non-paginated response - wrap it
|
||||
return {
|
||||
...response,
|
||||
data: {
|
||||
count: response.data.length,
|
||||
next: null,
|
||||
previous: null,
|
||||
results: response.data,
|
||||
},
|
||||
};
|
||||
}
|
||||
// Already paginated
|
||||
return response as typeof response & { data: PaginatedResponse<Device> };
|
||||
},
|
||||
|
||||
getOne: (id: string) => apiClient.get<Device>(`/devices/${id}/`),
|
||||
|
||||
@@ -78,3 +95,37 @@ export const telemetryApi = {
|
||||
export const dashboardApi = {
|
||||
getOverview: () => apiClient.get<DashboardOverview>('/dashboard/overview/'),
|
||||
};
|
||||
|
||||
// Weather API
|
||||
export const weatherApi = {
|
||||
getCurrent: (params: { city?: string; lat?: number; lon?: number }) =>
|
||||
apiClient.get<{
|
||||
location: string;
|
||||
temperature: number;
|
||||
apparent_temperature: number;
|
||||
humidity: number;
|
||||
weather_description: string;
|
||||
weather_code: number;
|
||||
precipitation: number;
|
||||
rain: number;
|
||||
cloud_cover: number;
|
||||
wind_speed: number;
|
||||
wind_direction: number;
|
||||
time: string;
|
||||
timezone: string;
|
||||
}>('/weather/current/', { params }),
|
||||
|
||||
getAirQuality: (city: string) =>
|
||||
apiClient.get<{
|
||||
city: string;
|
||||
measurements: Record<string, {
|
||||
average: number;
|
||||
min: number;
|
||||
max: number;
|
||||
count: number;
|
||||
}>;
|
||||
status: string;
|
||||
timestamp: string;
|
||||
sensor_count: number;
|
||||
}>('/weather/air_quality/', { params: { city } }),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user