mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +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;
|
||||
@@ -1,7 +1,7 @@
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
import { z } from 'zod';
|
||||
|
||||
const validateEmail = async (email: string) => {
|
||||
const validateEmailRequest = async (email: string) => {
|
||||
const response = await fetch(`/api/users/check-email?email=${email}`);
|
||||
const json = await response.json();
|
||||
|
||||
@@ -22,4 +22,4 @@ const validateEmail = async (email: string) => {
|
||||
return !parsedPayload.data.emailIsTaken;
|
||||
};
|
||||
|
||||
export default validateEmail;
|
||||
export default validateEmailRequest;
|
||||
@@ -1,7 +1,7 @@
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
import { z } from 'zod';
|
||||
|
||||
const validateUsername = async (username: string) => {
|
||||
const validateUsernameRequest = async (username: string) => {
|
||||
const response = await fetch(`/api/users/check-username?username=${username}`);
|
||||
const json = await response.json();
|
||||
|
||||
@@ -22,4 +22,4 @@ const validateUsername = async (username: string) => {
|
||||
return !parsedPayload.data.usernameIsTaken;
|
||||
};
|
||||
|
||||
export default validateUsername;
|
||||
export default validateUsernameRequest;
|
||||
Reference in New Issue
Block a user