Files
the-biergarten-app/services/BeerPost/getAllBeerPosts.ts
Aaron William Po 0b96c8f1f5 Did more work to beer post page, seed
Worked on comments and beer recs features. Fine tuning database seed amounts.
2023-01-29 21:53:05 -05:00

51 lines
973 B
TypeScript

import DBClient from '@/prisma/DBClient';
import BeerPostQueryResult from './types/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;