rework vehicle handling
This commit is contained in:
@@ -216,6 +216,9 @@ export const incidentsApi = {
|
||||
const response = await api.get<{ success: boolean; data: IncidentListResponse }>(
|
||||
`/api/incidents?${params.toString()}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -227,6 +230,9 @@ export const incidentsApi = {
|
||||
const response = await api.get<{ success: boolean; data: EinsatzStats }>(
|
||||
`/api/incidents/stats${params}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -237,6 +243,9 @@ export const incidentsApi = {
|
||||
const response = await api.get<{ success: boolean; data: EinsatzDetail }>(
|
||||
`/api/incidents/${id}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -248,6 +257,9 @@ export const incidentsApi = {
|
||||
'/api/incidents',
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -259,6 +271,9 @@ export const incidentsApi = {
|
||||
`/api/incidents/${id}`,
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
|
||||
@@ -55,10 +55,13 @@ export const membersService = {
|
||||
const response = await api.get<ApiListResponse<MemberListItem>>(
|
||||
`/api/members?${params.toString()}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return {
|
||||
items: response.data.data,
|
||||
total: response.data.meta.total,
|
||||
page: response.data.meta.page,
|
||||
total: response.data.meta?.total ?? 0,
|
||||
page: response.data.meta?.page ?? 1,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -69,6 +72,9 @@ export const membersService = {
|
||||
const response = await api.get<ApiItemResponse<MemberWithProfile>>(
|
||||
`/api/members/${userId}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -84,6 +90,9 @@ export const membersService = {
|
||||
`/api/members/${userId}/profile`,
|
||||
data
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -100,6 +109,9 @@ export const membersService = {
|
||||
`/api/members/${userId}`,
|
||||
data
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -108,6 +120,9 @@ export const membersService = {
|
||||
*/
|
||||
async getMemberStats(): Promise<MemberStats> {
|
||||
const response = await api.get<ApiItemResponse<MemberStats>>('/api/members/stats');
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -15,6 +15,9 @@ async function unwrap<T>(
|
||||
promise: ReturnType<typeof api.get<{ success: boolean; data: T }>>
|
||||
): Promise<T> {
|
||||
const response = await promise;
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
@@ -44,6 +47,9 @@ export const vehiclesApi = {
|
||||
'/api/vehicles',
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -52,6 +58,9 @@ export const vehiclesApi = {
|
||||
`/api/vehicles/${id}`,
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -74,6 +83,9 @@ export const vehiclesApi = {
|
||||
`/api/vehicles/${id}/wartung`,
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user