mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Refactor: rename [:id] to [:postId] for api routes
This commit is contained in:
@@ -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,
|
||||
);
|
||||
44
src/pages/api/breweries/[postId]/comments/[commentId].ts
Normal file
44
src/pages/api/breweries/[postId]/comments/[commentId].ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import getCurrentUser from '@/config/nextConnect/middleware/getCurrentUser';
|
||||
import validateRequest from '@/config/nextConnect/middleware/validateRequest';
|
||||
import NextConnectOptions from '@/config/nextConnect/NextConnectOptions';
|
||||
|
||||
import {
|
||||
checkIfBreweryCommentOwner,
|
||||
deleteBreweryPostComment,
|
||||
editBreweryPostComment,
|
||||
} from '@/controllers/comments/brewery-comments';
|
||||
import { CommentRequest } from '@/controllers/comments/types';
|
||||
|
||||
import CreateCommentValidationSchema from '@/services/schema/CommentSchema/CreateCommentValidationSchema';
|
||||
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { createRouter } from 'next-connect';
|
||||
import { z } from 'zod';
|
||||
|
||||
const router = createRouter<
|
||||
CommentRequest,
|
||||
NextApiResponse<z.infer<typeof APIResponseValidationSchema>>
|
||||
>();
|
||||
|
||||
router
|
||||
.delete(
|
||||
validateRequest({
|
||||
querySchema: z.object({ commentId: z.string().cuid(), postId: z.string().cuid() }),
|
||||
}),
|
||||
getCurrentUser,
|
||||
checkIfBreweryCommentOwner,
|
||||
deleteBreweryPostComment,
|
||||
)
|
||||
.put(
|
||||
validateRequest({
|
||||
querySchema: z.object({ commentId: z.string().cuid(), postId: z.string().cuid() }),
|
||||
bodySchema: CreateCommentValidationSchema,
|
||||
}),
|
||||
getCurrentUser,
|
||||
checkIfBreweryCommentOwner,
|
||||
editBreweryPostComment,
|
||||
);
|
||||
|
||||
const handler = router.handler(NextConnectOptions);
|
||||
export default handler;
|
||||
@@ -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,
|
||||
);
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user