Refactor: update beer post services, comment services

This commit is contained in:
Aaron William Po
2023-12-11 21:16:33 -05:00
parent 80404802dc
commit f7d09ce61e
27 changed files with 410 additions and 517 deletions

View File

@@ -3,12 +3,12 @@ import Head from 'next/head';
import React from 'react';
import withPageAuthRequired from '@/util/withPageAuthRequired';
import getBeerPostById from '@/services/posts/beer-post/getBeerPostById';
import BeerPostQueryResult from '@/services/posts/beer-post/schema/BeerPostQueryResult';
import EditBeerPostForm from '@/components/EditBeerPostForm';
import FormPageLayout from '@/components/ui/forms/FormPageLayout';
import { BiBeer } from 'react-icons/bi';
import { z } from 'zod';
import { getBeerPostById } from '@/services/posts/beer-post';
interface EditPageProps {
beerPost: z.infer<typeof BeerPostQueryResult>;
@@ -37,7 +37,6 @@ const EditBeerPostPage: NextPage<EditPageProps> = ({ beerPost }) => {
ibu: beerPost.ibu,
description: beerPost.description,
id: beerPost.id,
styleId: beerPost.style.id,
}}
/>
</FormPageLayout>
@@ -50,7 +49,7 @@ export default EditBeerPostPage;
export const getServerSideProps = withPageAuthRequired<EditPageProps>(
async (context, session) => {
const beerPostId = context.params?.id as string;
const beerPost = await getBeerPostById(beerPostId);
const beerPost = await getBeerPostById({ beerPostId });
const { id: userId } = session;
if (!beerPost) {

View File

@@ -1,6 +1,5 @@
import { NextPage, GetServerSideProps } from 'next';
import Head from 'next/head';
import getBeerPostById from '@/services/posts/beer-post/getBeerPostById';
import BeerPostQueryResult from '@/services/posts/beer-post/schema/BeerPostQueryResult';
@@ -12,6 +11,7 @@ import useMediaQuery from '@/hooks/utilities/useMediaQuery';
import { Tab } from '@headlessui/react';
import dynamic from 'next/dynamic';
import { CldImage } from 'next-cloudinary';
import { getBeerPostById } from '@/services/posts/beer-post';
const [BeerInfoHeader, BeerPostCommentsSection, BeerRecommendations] = [
dynamic(() => import('@/components/BeerById/BeerInfoHeader')),
@@ -100,7 +100,9 @@ const BeerByIdPage: NextPage<BeerPageProps> = ({ beerPost }) => {
};
export const getServerSideProps: GetServerSideProps<BeerPageProps> = async (context) => {
const beerPost = await getBeerPostById(context.params!.id! as string);
const beerPost = await getBeerPostById({
beerPostId: context.params?.id as string,
});
if (!beerPost) {
return { notFound: true };