Files
the-biergarten-app/services/BeerPost/getAllBeerPosts.ts
Aaron William Po 5cf2087cd1 Refactored api services into sep files. Client fix
Fixed hydration errors in beers/[id] by implementing timeDistanceState
2023-01-31 23:16:43 -05:00

51 lines
974 B
TypeScript

import DBClient from '@/prisma/DBClient';
import BeerPostQueryResult from './schema/BeerPostQueryResult';
const prisma = DBClient.instance;
const getAllBeerPosts = async (pageNum: number, pageSize: number) => {
const skip = (pageNum - 1) * pageSize;
const beerPosts: BeerPostQueryResult[] = await prisma.beerPost.findMany({
select: {
id: true,
name: true,
type: {
select: {
name: true,
id: true,
},
},
ibu: true,
abv: true,
brewery: {
select: {
name: true,
id: true,
},
},
description: true,
createdAt: true,
postedBy: {
select: {
id: true,
username: true,
},
},
beerImages: {
select: {
url: true,
id: true,
alt: true,
},
},
},
take: pageSize,
skip,
});
return beerPosts;
};
export default getAllBeerPosts;