mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
29 lines
915 B
TypeScript
29 lines
915 B
TypeScript
import DBClient from '@/prisma/DBClient';
|
|
import BeerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
|
|
import { z } from 'zod';
|
|
import CommentQueryResult from '../schema/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 CommentQueryResult>[] =
|
|
await DBClient.instance.beerComment.findMany({
|
|
skip,
|
|
take: pageSize,
|
|
where: { beerPostId: id },
|
|
select: {
|
|
id: true,
|
|
content: true,
|
|
rating: true,
|
|
createdAt: true,
|
|
postedBy: { select: { id: true, username: true, createdAt: true } },
|
|
},
|
|
orderBy: { createdAt: 'desc' },
|
|
});
|
|
return beerComments;
|
|
};
|
|
|
|
export default getAllBeerComments;
|