Files
the-biergarten-app/src/services/BeerComment/getAllBeerComments.ts
2023-11-05 22:04:55 -05:00

35 lines
842 B
TypeScript

import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import CommentQueryResult from '../schema/CommentSchema/CommentQueryResult';
interface GetAllBeerCommentsArgs {
beerPostId: string;
pageNum: number;
pageSize: number;
}
const getAllBeerComments = async ({
beerPostId,
pageNum,
pageSize,
}: GetAllBeerCommentsArgs): Promise<z.infer<typeof CommentQueryResult>[]> => {
return DBClient.instance.beerComment.findMany({
skip: (pageNum - 1) * pageSize,
take: pageSize,
where: { beerPostId },
orderBy: { createdAt: 'desc' },
select: {
id: true,
content: true,
rating: true,
createdAt: true,
updatedAt: true,
postedBy: {
select: { id: true, username: true, createdAt: true, userAvatar: true },
},
},
});
};
export default getAllBeerComments;