Update api routes and begin to extract controllers out of routing logic

This commit is contained in:
Aaron William Po
2023-12-03 11:51:54 -05:00
parent 080eb4c3c3
commit b45ed857d3
16 changed files with 345 additions and 408 deletions

View File

@@ -10,7 +10,7 @@ import { createRouter } from 'next-connect';
import { z } from 'zod';
import getCurrentUser from '@/config/nextConnect/middleware/getCurrentUser';
import { NextApiResponse } from 'next';
import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult';
import CreateCommentValidationSchema from '@/services/schema/CommentSchema/CreateCommentValidationSchema';
interface CreateCommentRequest extends UserExtendedNextApiRequest {
@@ -30,7 +30,7 @@ const createComment = async (
const beerPostId = req.query.id;
const newBeerComment: z.infer<typeof CommentQueryResult> = await createNewBeerComment({
const newBeerComment = await createNewBeerComment({
content,
rating,
beerPostId,

View File

@@ -20,8 +20,8 @@ interface EditBeerPostRequest extends BeerPostRequest {
body: z.infer<typeof EditBeerPostValidationSchema>;
}
const checkIfBeerPostOwner = async (
req: BeerPostRequest,
const checkIfBeerPostOwner = async <BeerPostRequestType extends BeerPostRequest>(
req: BeerPostRequestType,
res: NextApiResponse,
next: NextHandler,
) => {