mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-05 18:09:04 +00:00
Refactor: Organize api requests by type and remove toastContext
This commit is contained in:
22
src/requests/BeerPost/deleteBeerPostRequest.ts
Normal file
22
src/requests/BeerPost/deleteBeerPostRequest.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
|
||||
const deleteBeerPostRequest = async (id: string) => {
|
||||
const response = await fetch(`/api/beers/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
|
||||
if (!parsed.success) {
|
||||
throw new Error('Could not successfully parse the response.');
|
||||
}
|
||||
|
||||
return parsed;
|
||||
};
|
||||
|
||||
export default deleteBeerPostRequest;
|
||||
Reference in New Issue
Block a user