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:
2025-11-14 00:45:10 +01:00
parent ed105fccd3
commit 7f2aec96dd
34 changed files with 1186 additions and 426 deletions

View File

@@ -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 } }),
};