mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
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:
@@ -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(),
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
28
src/services/BreweryComment/getAllBreweryComments.ts
Normal file
28
src/services/BreweryComment/getAllBreweryComments.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||
import { z } from 'zod';
|
||||
import CommentQueryResult from '../types/CommentSchema/CommentQueryResult';
|
||||
|
||||
const getAllBreweryComments = async (
|
||||
{ id }: Pick<z.infer<typeof beerPostQueryResult>, 'id'>,
|
||||
{ pageSize, pageNum = 0 }: { pageSize: number; pageNum?: number },
|
||||
) => {
|
||||
const skip = (pageNum - 1) * pageSize;
|
||||
const breweryComments: z.infer<typeof CommentQueryResult>[] =
|
||||
await DBClient.instance.breweryComment.findMany({
|
||||
skip,
|
||||
take: pageSize,
|
||||
where: { breweryPostId: id },
|
||||
select: {
|
||||
id: true,
|
||||
content: true,
|
||||
rating: true,
|
||||
createdAt: true,
|
||||
postedBy: { select: { id: true, username: true, createdAt: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
return breweryComments;
|
||||
};
|
||||
|
||||
export default getAllBreweryComments;
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const BeerCommentQueryResult = z.object({
|
||||
const CommentQueryResult = z.object({
|
||||
id: z.string().uuid(),
|
||||
content: z.string().min(1).max(500),
|
||||
rating: z.number().int().min(1).max(5),
|
||||
@@ -11,4 +11,4 @@ const BeerCommentQueryResult = z.object({
|
||||
}),
|
||||
});
|
||||
|
||||
export default BeerCommentQueryResult;
|
||||
export default CommentQueryResult;
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const BeerCommentValidationSchema = z.object({
|
||||
const CreateCommentValidationSchema = z.object({
|
||||
content: z
|
||||
.string()
|
||||
.min(1, { message: 'Comment must not be empty.' })
|
||||
@@ -12,4 +12,4 @@ const BeerCommentValidationSchema = z.object({
|
||||
.max(5, { message: 'Rating must be less than 5.' }),
|
||||
});
|
||||
|
||||
export default BeerCommentValidationSchema;
|
||||
export default CreateCommentValidationSchema;
|
||||
Reference in New Issue
Block a user