mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-06 02:19:05 +00:00
Refactor: Organize api requests by type and remove toastContext
This commit is contained in:
18
src/requests/BreweryPostLike/sendBreweryPostLikeRequest.ts
Normal file
18
src/requests/BreweryPostLike/sendBreweryPostLikeRequest.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
|
||||
const sendBreweryPostLikeRequest = async (breweryPostId: string) => {
|
||||
const response = await fetch(`/api/breweries/${breweryPostId}/like`, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
if (!parsed.success) {
|
||||
throw new Error('Invalid API response.');
|
||||
}
|
||||
|
||||
return parsed.data;
|
||||
};
|
||||
|
||||
export default sendBreweryPostLikeRequest;
|
||||
Reference in New Issue
Block a user