rework vehicle handling
This commit is contained in:
@@ -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