mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Refactored api services into sep files. Client fix
Fixed hydration errors in beers/[id] by implementing timeDistanceState
This commit is contained in:
37
services/BeerComment/getAllBeerComments.ts
Normal file
37
services/BeerComment/getAllBeerComments.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
import BeerPostQueryResult from '../BeerPost/schema/BeerPostQueryResult';
|
||||
import { BeerCommentQueryResultArrayT } from './schema/BeerCommentQueryResult';
|
||||
|
||||
const getAllBeerComments = async (
|
||||
{ id }: Pick<BeerPostQueryResult, 'id'>,
|
||||
{ pageSize, pageNum = 0 }: { pageSize: number; pageNum?: number },
|
||||
) => {
|
||||
const skip = (pageNum - 1) * pageSize;
|
||||
const beerComments: BeerCommentQueryResultArrayT =
|
||||
await DBClient.instance.beerComment.findMany({
|
||||
where: {
|
||||
beerPostId: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
content: true,
|
||||
rating: true,
|
||||
createdAt: true,
|
||||
postedBy: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
createdAt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
skip,
|
||||
take: pageSize,
|
||||
});
|
||||
return beerComments;
|
||||
};
|
||||
|
||||
export default getAllBeerComments;
|
||||
Reference in New Issue
Block a user