mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Formatting changes
This commit is contained in:
@@ -3,11 +3,15 @@ import BeerCommentValidationSchema from '@/services/BeerComment/schema/CreateBee
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
import { z } from 'zod';
|
||||
|
||||
const BeerCommentValidationSchemaWithId = BeerCommentValidationSchema.extend({
|
||||
beerPostId: z.string().uuid(),
|
||||
});
|
||||
|
||||
const sendCreateBeerCommentRequest = async ({
|
||||
beerPostId,
|
||||
content,
|
||||
rating,
|
||||
}: z.infer<typeof BeerCommentValidationSchema>) => {
|
||||
}: z.infer<typeof BeerCommentValidationSchemaWithId>) => {
|
||||
const response = await fetch(`/api/beers/${beerPostId}/comments`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -29,7 +33,6 @@ const sendCreateBeerCommentRequest = async ({
|
||||
const parsedResponse = APIResponseValidationSchema.safeParse(data);
|
||||
|
||||
if (!parsedResponse.success) {
|
||||
console.log(parsedResponse.error);
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
|
||||
@@ -37,7 +40,6 @@ const sendCreateBeerCommentRequest = async ({
|
||||
const parsedPayload = BeerCommentQueryResult.safeParse(parsedResponse.data.payload);
|
||||
|
||||
if (!parsedPayload.success) {
|
||||
console.log(parsedPayload.error);
|
||||
throw new Error('Invalid API response payload');
|
||||
}
|
||||
|
||||
|
||||
@@ -7,21 +7,21 @@ const sendCreateBeerPostRequest = async (
|
||||
) => {
|
||||
const response = await fetch('/api/beers/create', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
|
||||
if (!parsed.success) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
|
||||
const { payload } = parsed.data;
|
||||
const { payload, success, message } = parsed.data;
|
||||
|
||||
if (!success) {
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if (
|
||||
!(
|
||||
|
||||
Reference in New Issue
Block a user