Refactor: rename [:id] to [:postId] for api routes

This commit is contained in:
Aaron William Po
2023-12-24 12:34:51 -05:00
parent b21924b89c
commit 0e99782557
36 changed files with 118 additions and 105 deletions

View File

@@ -33,14 +33,18 @@ const BeerPostCommentsSection: FC<BeerPostCommentsSectionProps> = ({ beerPost })
const commentSectionRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
const handleDeleteRequest = async (id: string) => {
deleteBeerPostCommentRequest({ commentId: id });
await deleteBeerPostCommentRequest({ commentId: id, beerPostId: beerPost.id });
};
const handleEditRequest = async (
id: string,
data: z.infer<typeof CreateCommentValidationSchema>,
) => {
editBeerPostCommentRequest({ body: data, commentId: id });
await editBeerPostCommentRequest({
body: data,
commentId: id,
beerPostId: beerPost.id,
});
};
return (

View File

@@ -28,7 +28,7 @@ const BeerStyleCommentsSection: FC<BeerStyleCommentsSectionProps> = ({ beerStyle
const commentSectionRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
const handleDeleteRequest = async (id: string) => {
const response = await fetch(`/api/beer-style-comments/${id}`, {
const response = await fetch(`/api/beers/styles/${beerStyle.id}/comments/${id}`, {
method: 'DELETE',
});
@@ -41,7 +41,7 @@ const BeerStyleCommentsSection: FC<BeerStyleCommentsSectionProps> = ({ beerStyle
id: string,
data: z.infer<typeof CreateCommentValidationSchema>,
) => {
const response = await fetch(`/api/beer-style-comments/${id}`, {
const response = await fetch(`/api/beers/styles/${beerStyle.id}/comments/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: data.content, rating: data.rating }),

View File

@@ -31,9 +31,10 @@ const BreweryCommentsSection: FC<BreweryBeerSectionProps> = ({ breweryPost }) =>
const commentSectionRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
const handleDeleteRequest = async (commentId: string) => {
const response = await fetch(`/api/brewery-comments/${commentId}`, {
method: 'DELETE',
});
const response = await fetch(
`/api/breweries/${breweryPost.id}/comments/${commentId}`,
{ method: 'DELETE' },
);
if (!response.ok) {
throw new Error(response.statusText);
@@ -44,15 +45,19 @@ const BreweryCommentsSection: FC<BreweryBeerSectionProps> = ({ breweryPost }) =>
commentId: string,
data: z.infer<typeof CreateCommentValidationSchema>,
) => {
const response = await fetch(`/api/brewery-comments/${commentId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: data.content, rating: data.rating }),
});
const response = await fetch(
`/api/breweries/${breweryPost.id}/comments/${commentId}`,
{
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: data.content, rating: data.rating }),
},
);
if (!response.ok) {
throw new Error(response.statusText);
}
console.log(await response.json());
};
return (

View File

@@ -24,9 +24,9 @@ export const checkIfBeerCommentOwner = async <T extends CommentRequest>(
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
next: NextHandler,
) => {
const { id } = req.query;
const { commentId } = req.query;
const user = req.user!;
const comment = await getBeerPostCommentByIdService({ beerPostCommentId: id });
const comment = await getBeerPostCommentByIdService({ beerPostCommentId: commentId });
if (!comment) {
throw new ServerError('Comment not found', 404);
@@ -43,9 +43,9 @@ export const editBeerPostComment = async (
req: EditAndCreateCommentRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const { id } = req.query;
const { commentId } = req.query;
await editBeerPostCommentByIdService({ body: req.body, beerPostCommentId: id });
await editBeerPostCommentByIdService({ body: req.body, beerPostCommentId: commentId });
res.status(200).json({
success: true,
@@ -58,9 +58,9 @@ export const deleteBeerPostComment = async (
req: CommentRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const { id } = req.query;
const { commentId } = req.query;
await deleteBeerCommentByIdService({ beerPostCommentId: id });
await deleteBeerCommentByIdService({ beerPostCommentId: commentId });
res.status(200).json({
success: true,
@@ -73,7 +73,7 @@ export const createBeerPostComment = async (
req: EditAndCreateCommentRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const beerPostId = req.query.id;
const beerPostId = req.query.postId;
const newBeerComment = await createBeerPostCommentService({
body: req.body,
@@ -93,7 +93,7 @@ export const getAllBeerPostComments = async (
req: GetAllCommentsRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const beerPostId = req.query.id;
const beerPostId = req.query.postId;
// eslint-disable-next-line @typescript-eslint/naming-convention
const { page_size, page_num } = req.query;

View File

@@ -25,10 +25,12 @@ export const checkIfBeerStyleCommentOwner = async <
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
next: NextHandler,
) => {
const { id } = req.query;
const { commentId } = req.query;
const user = req.user!;
const beerStyleComment = await findBeerStyleCommentById({ beerStyleCommentId: id });
const beerStyleComment = await findBeerStyleCommentById({
beerStyleCommentId: commentId,
});
if (!beerStyleComment) {
throw new ServerError('Beer style comment not found.', 404);
@@ -49,7 +51,7 @@ export const editBeerStyleComment = async (
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
await updateBeerStyleCommentById({
beerStyleCommentId: req.query.id,
beerStyleCommentId: req.query.commentId,
body: req.body,
});
@@ -64,9 +66,9 @@ export const deleteBeerStyleComment = async (
req: CommentRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const { id } = req.query;
const { commentId } = req.query;
await deleteBeerStyleCommentById({ beerStyleCommentId: id });
await deleteBeerStyleCommentById({ beerStyleCommentId: commentId });
res.status(200).json({
success: true,
@@ -81,7 +83,7 @@ export const createComment = async (
) => {
const newBeerStyleComment = await createNewBeerStyleComment({
body: req.body,
beerStyleId: req.query.id,
beerStyleId: req.query.postId,
userId: req.user!.id,
});
@@ -97,7 +99,7 @@ export const getAll = async (
req: GetAllCommentsRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const beerStyleId = req.query.id;
const beerStyleId = req.query.postId;
// eslint-disable-next-line @typescript-eslint/naming-convention
const { page_size, page_num } = req.query;

View File

@@ -25,9 +25,9 @@ export const checkIfBreweryCommentOwner = async <
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
next: NextHandler,
) => {
const { id } = req.query;
const { commentId } = req.query;
const user = req.user!;
const comment = await getBreweryCommentById({ breweryCommentId: id });
const comment = await getBreweryCommentById({ breweryCommentId: commentId });
if (!comment) {
throw new ServerError('Comment not found', 404);
@@ -44,10 +44,10 @@ export const editBreweryPostComment = async (
req: EditAndCreateCommentRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const { id } = req.query;
const { commentId } = req.query;
const updated = updateBreweryCommentById({
breweryCommentId: id,
const updated = await updateBreweryCommentById({
breweryCommentId: commentId,
body: req.body,
});
@@ -63,9 +63,9 @@ export const deleteBreweryPostComment = async (
req: CommentRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const { id } = req.query;
const { commentId } = req.query;
await deleteBreweryCommentByIdService({ breweryCommentId: id });
await deleteBreweryCommentByIdService({ breweryCommentId: commentId });
res.status(200).json({
success: true,
@@ -78,7 +78,7 @@ export const createComment = async (
req: EditAndCreateCommentRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const breweryPostId = req.query.id;
const breweryPostId = req.query.postId;
const user = req.user!;
@@ -100,7 +100,7 @@ export const getAll = async (
req: GetAllCommentsRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const breweryPostId = req.query.id;
const breweryPostId = req.query.postId;
// eslint-disable-next-line @typescript-eslint/naming-convention
const { page_size, page_num } = req.query;

View File

@@ -3,7 +3,7 @@ import CreateCommentValidationSchema from '@/services/schema/CommentSchema/Creat
import { z } from 'zod';
export interface CommentRequest extends UserExtendedNextApiRequest {
query: { id: string };
query: { postId: string; commentId: string };
}
export interface EditAndCreateCommentRequest extends CommentRequest {
@@ -11,5 +11,5 @@ export interface EditAndCreateCommentRequest extends CommentRequest {
}
export interface GetAllCommentsRequest extends UserExtendedNextApiRequest {
query: { id: string; page_size: string; page_num: string };
query: { postId: string; page_size: string; page_num: string };
}

View File

@@ -2,7 +2,7 @@ import { UserExtendedNextApiRequest } from '@/config/auth/types';
import ServerError from '@/config/util/ServerError';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import { NextApiResponse, NextApiRequest } from 'next';
import { NextApiResponse } from 'next';
import { z } from 'zod';
import { getBeerPostById } from '@/services/posts/beer-post';
@@ -19,9 +19,9 @@ export const sendBeerPostLikeRequest = async (
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const user = req.user!;
const id = req.query.id as string;
const { postId } = req.query;
const beer = await getBeerPostById({ beerPostId: id });
const beer = await getBeerPostById({ beerPostId: postId });
if (!beer) {
throw new ServerError('Could not find a beer post with that id.', 404);
}
@@ -53,12 +53,12 @@ export const sendBeerPostLikeRequest = async (
};
export const getBeerPostLikeCount = async (
req: NextApiRequest,
req: LikeRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const id = req.query.id as string;
const { postId } = req.query;
const likeCount = await getBeerPostLikeCountService({ beerPostId: id });
const likeCount = await getBeerPostLikeCountService({ beerPostId: postId });
res.status(200).json({
success: true,

View File

@@ -1,7 +1,7 @@
import ServerError from '@/config/util/ServerError';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import { NextApiResponse, NextApiRequest } from 'next';
import { NextApiResponse } from 'next';
import { z } from 'zod';
import { UserExtendedNextApiRequest } from '@/config/auth/types';
import {
@@ -18,9 +18,9 @@ export const sendBeerStyleLikeRequest = async (
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const user = req.user!;
const { id } = req.query;
const { postId } = req.query;
const beerStyle = await getBeerStyleByIdService({ beerStyleId: id });
const beerStyle = await getBeerStyleByIdService({ beerStyleId: postId });
if (!beerStyle) {
throw new ServerError('Could not find a beer style with that id.', 404);
}
@@ -48,11 +48,11 @@ export const sendBeerStyleLikeRequest = async (
};
export const getBeerStyleLikeCountRequest = async (
req: NextApiRequest,
req: LikeRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const id = req.query.id as string;
const likeCount = await getBeerStyleLikeCountService({ beerStyleId: id });
const { postId } = req.query;
const likeCount = await getBeerStyleLikeCountService({ beerStyleId: postId });
res.status(200).json({
success: true,

View File

@@ -1,4 +1,3 @@
import { UserExtendedNextApiRequest } from '@/config/auth/types';
import ServerError from '@/config/util/ServerError';
import {
@@ -9,17 +8,18 @@ import {
} from '@/services/likes/brewery-post-like';
import { getBreweryPostByIdService } from '@/services/posts/brewery-post';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import { NextApiResponse, NextApiRequest } from 'next';
import { NextApiResponse } from 'next';
import { z } from 'zod';
import { LikeRequest } from '../types';
export const sendBreweryPostLikeRequest = async (
req: UserExtendedNextApiRequest,
req: LikeRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const id = req.query.id! as string;
const { postId } = req.query;
const user = req.user!;
const breweryPost = await getBreweryPostByIdService({ breweryPostId: id });
const breweryPost = await getBreweryPostByIdService({ breweryPostId: postId });
if (!breweryPost) {
throw new ServerError('Could not find a brewery post with that id', 404);
@@ -53,12 +53,12 @@ export const sendBreweryPostLikeRequest = async (
};
export const getBreweryPostLikeCount = async (
req: NextApiRequest,
req: LikeRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const id = req.query.id! as string;
const { postId } = req.query;
const breweryPost = await getBreweryPostByIdService({ breweryPostId: id });
const breweryPost = await getBreweryPostByIdService({ breweryPostId: postId });
if (!breweryPost) {
throw new ServerError('Could not find a brewery post with that id', 404);
}
@@ -76,14 +76,14 @@ export const getBreweryPostLikeCount = async (
};
export const getBreweryPostLikeStatus = async (
req: UserExtendedNextApiRequest,
req: LikeRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const user = req.user!;
const id = req.query.id as string;
const { postId } = req.query;
const liked = await findBreweryPostLikeService({
breweryPostId: id,
breweryPostId: postId,
likedById: user.id,
});

View File

@@ -1,5 +1,5 @@
import { UserExtendedNextApiRequest } from '@/config/auth/types';
export interface LikeRequest extends UserExtendedNextApiRequest {
query: { id: string };
query: { postId: string };
}

View File

@@ -28,9 +28,9 @@ export const checkIfBeerPostOwner = async <BeerPostRequestType extends BeerPostR
next: NextHandler,
) => {
const { user, query } = req;
const { id } = query;
const { postId } = query;
const beerPost = await getBeerPostById({ beerPostId: id });
const beerPost = await getBeerPostById({ beerPostId: postId });
if (!beerPost) {
throw new ServerError('Beer post not found', 404);
@@ -47,7 +47,7 @@ export const editBeerPost = async (
req: EditBeerPostRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
await editBeerPostByIdService({ beerPostId: req.query.id, body: req.body });
await editBeerPostByIdService({ beerPostId: req.query.postId, body: req.body });
res.status(200).json({
message: 'Beer post updated successfully',
@@ -57,9 +57,9 @@ export const editBeerPost = async (
};
export const deleteBeerPost = async (req: BeerPostRequest, res: NextApiResponse) => {
const { id } = req.query;
const { postId } = req.query;
const deleted = await deleteBeerPostByIdService({ beerPostId: id });
const deleted = await deleteBeerPostByIdService({ beerPostId: postId });
if (!deleted) {
throw new ServerError('Beer post not found', 404);
}
@@ -75,9 +75,9 @@ export const getBeerPostRecommendations = async (
req: GetBeerRecommendationsRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const { id } = req.query;
const { postId } = req.query;
const beerPost = await getBeerPostById({ beerPostId: id });
const beerPost = await getBeerPostById({ beerPostId: postId });
if (!beerPost) {
throw new ServerError('Beer post not found', 404);

View File

@@ -5,7 +5,7 @@ import { NextApiRequest } from 'next';
import { z } from 'zod';
export interface BeerPostRequest extends UserExtendedNextApiRequest {
query: { id: string };
query: { postId: string };
}
export interface EditBeerPostRequest extends BeerPostRequest {
@@ -17,7 +17,7 @@ export interface GetAllBeerPostsRequest extends NextApiRequest {
}
export interface GetBeerRecommendationsRequest extends BeerPostRequest {
query: { id: string; page_num: string; page_size: string };
query: { postId: string; page_num: string; page_size: string };
}
export interface CreateBeerPostRequest extends UserExtendedNextApiRequest {

View File

@@ -41,7 +41,7 @@ const useGetBreweryPostLikeCount = (breweryPostId: string) => {
error: error as unknown,
isLoading,
mutate,
likeCount: data as number | undefined,
likeCount: data,
};
};

View File

@@ -22,14 +22,16 @@ const router = createRouter<
router
.delete(
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({
querySchema: z.object({ postId: z.string().cuid(), commentId: z.string().cuid() }),
}),
getCurrentUser,
checkIfBeerCommentOwner,
deleteBeerPostComment,
)
.put(
validateRequest({
querySchema: z.object({ id: z.string().cuid() }),
querySchema: z.object({ postId: z.string().cuid(), commentId: z.string().cuid() }),
bodySchema: CreateCommentValidationSchema,
}),
getCurrentUser,

View File

@@ -22,7 +22,7 @@ const router = createRouter<
router.post(
validateRequest({
bodySchema: CreateCommentValidationSchema,
querySchema: z.object({ id: z.string().cuid() }),
querySchema: z.object({ postId: z.string().cuid() }),
}),
getCurrentUser,
createBeerPostComment,
@@ -30,7 +30,7 @@ router.post(
router.get(
validateRequest({
querySchema: PaginatedQueryResponseSchema.extend({ id: z.string().cuid() }),
querySchema: PaginatedQueryResponseSchema.extend({ postId: z.string().cuid() }),
}),
getAllBeerPostComments,
);

View File

@@ -26,14 +26,14 @@ router
.put(
validateRequest({
bodySchema: EditBeerPostValidationSchema,
querySchema: z.object({ id: z.string() }),
querySchema: z.object({ postId: z.string() }),
}),
getCurrentUser,
checkIfBeerPostOwner,
editBeerPost,
)
.delete(
validateRequest({ querySchema: z.object({ id: z.string() }) }),
validateRequest({ querySchema: z.object({ postId: z.string() }) }),
getCurrentUser,
checkIfBeerPostOwner,
deleteBeerPost,

View File

@@ -19,12 +19,12 @@ const router = createRouter<
router.post(
getCurrentUser,
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
sendBeerPostLikeRequest,
);
router.get(
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
getBeerPostLikeCount,
);

View File

@@ -16,7 +16,7 @@ const router = createRouter<
router.get(
getCurrentUser,
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
checkIfBeerPostIsLiked,
);

View File

@@ -15,7 +15,7 @@ const router = createRouter<
router.get(
validateRequest({
querySchema: PaginatedQueryResponseSchema.extend({ id: z.string().cuid() }),
querySchema: PaginatedQueryResponseSchema.extend({ postId: z.string().cuid() }),
}),
getBeerPostRecommendations,
);

View File

@@ -19,7 +19,7 @@ const router = createRouter<
router.get(
validateRequest({
querySchema: PaginatedQueryResponseSchema.extend({ id: z.string().cuid() }),
querySchema: PaginatedQueryResponseSchema.extend({ postId: z.string().cuid() }),
}),
getAllBeersByBeerStyle,
);

View File

@@ -22,7 +22,7 @@ const router = createRouter<
router
.delete(
validateRequest({
querySchema: z.object({ id: z.string().cuid() }),
querySchema: z.object({ postId: z.string().cuid(), commentId: z.string().cuid() }),
}),
getCurrentUser,
checkIfBeerStyleCommentOwner,
@@ -30,7 +30,7 @@ router
)
.put(
validateRequest({
querySchema: z.object({ id: z.string().cuid() }),
querySchema: z.object({ postId: z.string().cuid(), commentId: z.string().cuid() }),
bodySchema: CreateCommentValidationSchema,
}),
getCurrentUser,

View File

@@ -19,7 +19,7 @@ const router = createRouter<
router.post(
validateRequest({
bodySchema: CreateCommentValidationSchema,
querySchema: z.object({ id: z.string().cuid() }),
querySchema: z.object({ postId: z.string().cuid() }),
}),
getCurrentUser,
createComment,
@@ -27,7 +27,7 @@ router.post(
router.get(
validateRequest({
querySchema: PaginatedQueryResponseSchema.extend({ id: z.string().cuid() }),
querySchema: PaginatedQueryResponseSchema.extend({ postId: z.string().cuid() }),
}),
getAll,
);

View File

@@ -13,7 +13,7 @@ const router = createRouter<
>();
router.get(
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
getBeerStyle,
);

View File

@@ -20,12 +20,12 @@ const router = createRouter<
router.post(
getCurrentUser,
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
sendBeerStyleLikeRequest,
);
router.get(
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
getBeerStyleLikeCountRequest,
);

View File

@@ -15,7 +15,7 @@ const router = createRouter<
router.get(
getCurrentUser,
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
checkIfBeerStyleIsLiked,
);

View File

@@ -15,7 +15,7 @@ const router = createRouter<
router.get(
validateRequest({
querySchema: PaginatedQueryResponseSchema.extend({ id: z.string().cuid() }),
querySchema: PaginatedQueryResponseSchema.extend({ postId: z.string().cuid() }),
}),
getAllBeersByBrewery,
);

View File

@@ -24,7 +24,7 @@ const router = createRouter<
router
.delete(
validateRequest({
querySchema: z.object({ id: z.string().cuid() }),
querySchema: z.object({ commentId: z.string().cuid(), postId: z.string().cuid() }),
}),
getCurrentUser,
checkIfBreweryCommentOwner,
@@ -32,7 +32,7 @@ router
)
.put(
validateRequest({
querySchema: z.object({ id: z.string().cuid() }),
querySchema: z.object({ commentId: z.string().cuid(), postId: z.string().cuid() }),
bodySchema: CreateCommentValidationSchema,
}),
getCurrentUser,

View File

@@ -20,7 +20,7 @@ const router = createRouter<
router.post(
validateRequest({
bodySchema: CreateCommentValidationSchema,
querySchema: z.object({ id: z.string().cuid() }),
querySchema: z.object({ postId: z.string().cuid() }),
}),
getCurrentUser,
createComment,
@@ -28,7 +28,7 @@ router.post(
router.get(
validateRequest({
querySchema: PaginatedQueryResponseSchema.extend({ id: z.string().cuid() }),
querySchema: PaginatedQueryResponseSchema.extend({ postId: z.string().cuid() }),
}),
getAll,
);

View File

@@ -19,12 +19,12 @@ const router = createRouter<
router.post(
getCurrentUser,
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
sendBreweryPostLikeRequest,
);
router.get(
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
getBreweryPostLikeCount,
);

View File

@@ -16,11 +16,7 @@ const router = createRouter<
router.get(
getCurrentUser,
validateRequest({
querySchema: z.object({
id: z.string().cuid(),
}),
}),
validateRequest({ querySchema: z.object({ postId: z.string().cuid() }) }),
getBreweryPostLikeStatus,
);

View File

@@ -9,8 +9,9 @@ import {
export const editBeerPostCommentRequest: SendEditBeerPostCommentRequest = async ({
body,
commentId,
beerPostId,
}) => {
const response = await fetch(`/api/beer-post-comments/${commentId}`, {
const response = await fetch(`/api/beers/${beerPostId}/comments/${commentId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
@@ -33,8 +34,9 @@ export const editBeerPostCommentRequest: SendEditBeerPostCommentRequest = async
export const deleteBeerPostCommentRequest: SendDeleteBeerPostCommentRequest = async ({
commentId,
beerPostId,
}) => {
const response = await fetch(`/api/beer-post-comments/${commentId}`, {
const response = await fetch(`/api/beers/${beerPostId}/comments/${commentId}`, {
method: 'DELETE',
});

View File

@@ -5,10 +5,12 @@ import { z } from 'zod';
export type SendEditBeerPostCommentRequest = (args: {
body: { content: string; rating: number };
commentId: string;
beerPostId: string;
}) => Promise<z.infer<typeof APIResponseValidationSchema>>;
export type SendDeleteBeerPostCommentRequest = (args: {
commentId: string;
beerPostId: string;
}) => Promise<z.infer<typeof APIResponseValidationSchema>>;
export type SendCreateBeerCommentRequest = (args: {