Refactor: update types for brewery comments

This commit is contained in:
Aaron William Po
2023-10-07 15:21:57 -04:00
parent 2ee12d351f
commit 3b626e2f95
13 changed files with 3388 additions and 3517 deletions

View File

@@ -61,10 +61,11 @@ const getAll = async (
// eslint-disable-next-line @typescript-eslint/naming-convention
const { page_size, page_num } = req.query;
const comments = await getAllBreweryComments(
{ id: breweryPostId },
{ pageSize: parseInt(page_size, 10), pageNum: parseInt(page_num, 10) },
);
const comments = await getAllBreweryComments({
id: breweryPostId,
pageNum: parseInt(page_num, 10),
pageSize: parseInt(page_size, 10),
});
const pageCount = await DBClient.instance.breweryComment.count({
where: { breweryPostId },

View File

@@ -4,6 +4,7 @@ import validateRequest from '@/config/nextConnect/middleware/validateRequest';
import NextConnectOptions from '@/config/nextConnect/NextConnectOptions';
import ServerError from '@/config/util/ServerError';
import DBClient from '@/prisma/DBClient';
import getBreweryCommentById from '@/services/BreweryComment/getBreweryCommentById';
import CreateCommentValidationSchema from '@/services/schema/CommentSchema/CreateCommentValidationSchema';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
@@ -27,9 +28,7 @@ const checkIfCommentOwner = async (
) => {
const { id } = req.query;
const user = req.user!;
const comment = await DBClient.instance.breweryComment.findUnique({
where: { id },
});
const comment = await getBreweryCommentById(id);
if (!comment) {
throw new ServerError('Comment not found', 404);
@@ -87,7 +86,9 @@ const router = createRouter<
router
.delete(
validateRequest({ querySchema: z.object({ id: z.string().cuid() }) }),
validateRequest({
querySchema: z.object({ id: z.string().cuid() }),
}),
getCurrentUser,
checkIfCommentOwner,
deleteComment,