mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Feat: Update beer recs to be loaded on the client side
This commit is contained in:
@@ -1,22 +1,51 @@
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||
import BeerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
const getBeerRecommendations = async (
|
||||
beerPost: Pick<z.infer<typeof beerPostQueryResult>, 'type' | 'brewery' | 'id'>,
|
||||
) => {
|
||||
const beerRecommendations = await DBClient.instance.beerPost.findMany({
|
||||
interface GetBeerRecommendationsArgs {
|
||||
beerPost: z.infer<typeof BeerPostQueryResult>;
|
||||
pageNum: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
const getBeerRecommendations = async ({
|
||||
beerPost,
|
||||
pageNum,
|
||||
pageSize,
|
||||
}: GetBeerRecommendationsArgs) => {
|
||||
const skip = (pageNum - 1) * pageSize;
|
||||
const take = pageSize;
|
||||
const beerRecommendations: z.infer<typeof BeerPostQueryResult>[] =
|
||||
await DBClient.instance.beerPost.findMany({
|
||||
where: {
|
||||
OR: [{ typeId: beerPost.type.id }, { breweryId: beerPost.brewery.id }],
|
||||
NOT: { id: beerPost.id },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
ibu: true,
|
||||
abv: true,
|
||||
description: true,
|
||||
createdAt: true,
|
||||
type: { select: { name: true, id: true } },
|
||||
brewery: { select: { name: true, id: true } },
|
||||
postedBy: { select: { id: true, username: true } },
|
||||
beerImages: { select: { path: true, caption: true, id: true, alt: true } },
|
||||
},
|
||||
take,
|
||||
skip,
|
||||
});
|
||||
|
||||
const count = await DBClient.instance.beerPost.count({
|
||||
where: {
|
||||
OR: [{ typeId: beerPost.type.id }, { breweryId: beerPost.brewery.id }],
|
||||
NOT: { id: beerPost.id },
|
||||
},
|
||||
include: {
|
||||
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
|
||||
brewery: { select: { id: true, name: true } },
|
||||
},
|
||||
});
|
||||
|
||||
return beerRecommendations;
|
||||
return { beerRecommendations, count };
|
||||
};
|
||||
|
||||
export default getBeerRecommendations;
|
||||
|
||||
Reference in New Issue
Block a user