Feat: Implement infinite scrolling brewery comment section

Refactor beer comment schemas to work on brewery comments as well. Add robots.txt to block crawling for now.
This commit is contained in:
Aaron William Po
2023-04-30 13:43:51 -04:00
parent 99e3eba7d6
commit b3b1d5b6d1
27 changed files with 670 additions and 261 deletions

View File

@@ -1,8 +1,8 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import BeerCommentValidationSchema from './schema/CreateBeerCommentValidationSchema';
import CreateCommentValidationSchema from '../types/CommentSchema/CreateCommentValidationSchema';
const CreateNewBeerCommentServiceSchema = BeerCommentValidationSchema.extend({
const CreateNewBeerCommentServiceSchema = CreateCommentValidationSchema.extend({
userId: z.string().uuid(),
beerPostId: z.string().uuid(),
});

View File

@@ -1,14 +1,14 @@
import DBClient from '@/prisma/DBClient';
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
import { z } from 'zod';
import BeerCommentQueryResult from './schema/BeerCommentQueryResult';
import CommentQueryResult from '../types/CommentSchema/CommentQueryResult';
const getAllBeerComments = async (
{ id }: Pick<z.infer<typeof beerPostQueryResult>, 'id'>,
{ pageSize, pageNum = 0 }: { pageSize: number; pageNum?: number },
) => {
const skip = (pageNum - 1) * pageSize;
const beerComments: z.infer<typeof BeerCommentQueryResult>[] =
const beerComments: z.infer<typeof CommentQueryResult>[] =
await DBClient.instance.beerComment.findMany({
skip,
take: pageSize,

View File

@@ -1,14 +0,0 @@
import { z } from 'zod';
const BeerCommentQueryResult = z.object({
id: z.string().uuid(),
content: z.string().min(1).max(500),
rating: z.number().int().min(1).max(5),
createdAt: z.coerce.date(),
postedBy: z.object({
id: z.string().uuid(),
username: z.string().min(1).max(50),
}),
});
export default BeerCommentQueryResult;

View File

@@ -1,15 +0,0 @@
import { z } from 'zod';
const BeerCommentValidationSchema = z.object({
content: z
.string()
.min(1, { message: 'Comment must not be empty.' })
.max(300, { message: 'Comment must be less than 300 characters.' }),
rating: z
.number()
.int()
.min(1, { message: 'Rating must be greater than 1.' })
.max(5, { message: 'Rating must be less than 5.' }),
});
export default BeerCommentValidationSchema;