mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
cleanup
This commit is contained in:
@@ -45,12 +45,7 @@ const editBeerPost = async (
|
||||
req: EditBeerPostRequest,
|
||||
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
|
||||
) => {
|
||||
const {
|
||||
body,
|
||||
query: { id },
|
||||
} = req;
|
||||
|
||||
await editBeerPostById(id, body);
|
||||
await editBeerPostById({ id: req.query.id, data: req.body });
|
||||
|
||||
res.status(200).json({
|
||||
message: 'Beer post updated successfully',
|
||||
@@ -62,8 +57,7 @@ const editBeerPost = async (
|
||||
const deleteBeerPost = async (req: BeerPostRequest, res: NextApiResponse) => {
|
||||
const { id } = req.query;
|
||||
|
||||
const deleted = deleteBeerPostById(id);
|
||||
|
||||
const deleted = deleteBeerPostById({ beerPostId: id });
|
||||
if (!deleted) {
|
||||
throw new ServerError('Beer post not found', 404);
|
||||
}
|
||||
@@ -74,26 +68,28 @@ const deleteBeerPost = async (req: BeerPostRequest, res: NextApiResponse) => {
|
||||
statusCode: 200,
|
||||
});
|
||||
};
|
||||
|
||||
const router = createRouter<
|
||||
EditBeerPostRequest,
|
||||
NextApiResponse<z.infer<typeof APIResponseValidationSchema>>
|
||||
>();
|
||||
|
||||
router.put(
|
||||
validateRequest({
|
||||
bodySchema: EditBeerPostValidationSchema,
|
||||
querySchema: z.object({ id: z.string() }),
|
||||
}),
|
||||
getCurrentUser,
|
||||
checkIfBeerPostOwner,
|
||||
editBeerPost,
|
||||
);
|
||||
router.delete(
|
||||
validateRequest({ querySchema: z.object({ id: z.string() }) }),
|
||||
getCurrentUser,
|
||||
checkIfBeerPostOwner,
|
||||
deleteBeerPost,
|
||||
);
|
||||
router
|
||||
.put(
|
||||
validateRequest({
|
||||
bodySchema: EditBeerPostValidationSchema,
|
||||
querySchema: z.object({ id: z.string() }),
|
||||
}),
|
||||
getCurrentUser,
|
||||
checkIfBeerPostOwner,
|
||||
editBeerPost,
|
||||
)
|
||||
.delete(
|
||||
validateRequest({ querySchema: z.object({ id: z.string() }) }),
|
||||
getCurrentUser,
|
||||
checkIfBeerPostOwner,
|
||||
deleteBeerPost,
|
||||
);
|
||||
|
||||
const handler = router.handler(NextConnectOptions);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ const getBeerPosts = async (
|
||||
const pageNum = parseInt(req.query.page_num, 10);
|
||||
const pageSize = parseInt(req.query.page_size, 10);
|
||||
|
||||
const beerPosts = await getAllBeerPosts(pageNum, pageSize);
|
||||
const beerPosts = await getAllBeerPosts({ pageNum, pageSize });
|
||||
const beerPostCount = await DBClient.instance.beerPost.count();
|
||||
|
||||
res.setHeader('X-Total-Count', beerPostCount);
|
||||
|
||||
@@ -26,6 +26,7 @@ const search = async (req: SearchAPIRequest, res: NextApiResponse) => {
|
||||
ibu: true,
|
||||
abv: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
description: true,
|
||||
postedBy: { select: { username: true, id: true } },
|
||||
brewery: { select: { name: true, id: true } },
|
||||
|
||||
@@ -29,6 +29,7 @@ const getAllBeersByBrewery = async (
|
||||
ibu: true,
|
||||
abv: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
description: true,
|
||||
postedBy: { select: { username: true, id: true } },
|
||||
brewery: { select: { name: true, id: true } },
|
||||
|
||||
@@ -19,7 +19,7 @@ const getBreweryPosts = async (
|
||||
const pageNum = parseInt(req.query.page_num, 10);
|
||||
const pageSize = parseInt(req.query.page_size, 10);
|
||||
|
||||
const breweryPosts = await getAllBreweryPosts(pageNum, pageSize);
|
||||
const breweryPosts = await getAllBreweryPosts({ pageNum, pageSize });
|
||||
const breweryPostCount = await DBClient.instance.breweryPost.count();
|
||||
|
||||
res.setHeader('X-Total-Count', breweryPostCount);
|
||||
|
||||
Reference in New Issue
Block a user