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

@@ -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 };
}