Did more work to beer post page, seed

Worked on comments and beer recs features. Fine tuning database seed amounts.
This commit is contained in:
Aaron William Po
2023-01-29 21:53:05 -05:00
parent fe277d5964
commit 0b96c8f1f5
38 changed files with 833 additions and 221 deletions

View File

@@ -0,0 +1,37 @@
import BeerCommentQueryResult from '@/services/BeerPost/types/BeerCommentQueryResult';
import DBClient from '@/prisma/DBClient';
import BeerPostQueryResult from './types/BeerPostQueryResult';
const getAllBeerComments = async (
{ id }: Pick<BeerPostQueryResult, 'id'>,
{ pageSize, pageNum = 0 }: { pageSize: number; pageNum?: number },
) => {
const skip = (pageNum - 1) * pageSize;
const beerComments: BeerCommentQueryResult[] =
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;

View File

@@ -32,19 +32,6 @@ const getAllBeerPosts = async (pageNum: number, pageSize: number) => {
username: true,
},
},
beerComments: {
select: {
id: true,
content: true,
createdAt: true,
postedBy: {
select: {
username: true,
id: true,
},
},
},
},
beerImages: {
select: {
url: true,

View File

@@ -17,6 +17,7 @@ const getBeerPostById = async (id: string) => {
id: true,
},
},
rating: true,
},
},
id: true,

View File

@@ -0,0 +1,31 @@
import BeerPostQueryResult from '@/services/BeerPost/types/BeerPostQueryResult';
import DBClient from '@/prisma/DBClient';
const getBeerRecommendations = async (
beerPost: Pick<BeerPostQueryResult, 'type' | 'brewery'>,
) => {
const beerRecommendations = await DBClient.instance.beerPost.findMany({
where: {
OR: [
{
typeId: beerPost.type.id,
},
{
breweryId: beerPost.brewery.id,
},
],
},
include: {
beerImages: {
select: { id: true, url: true, alt: true },
},
brewery: {
select: { id: true, name: true },
},
},
});
return beerRecommendations;
};
export default getBeerRecommendations;

View File

@@ -0,0 +1,13 @@
interface BeerCommentQueryResult {
id: string;
content: string;
rating: number;
createdAt: Date;
postedBy: {
id: string;
createdAt: Date;
username: string;
};
}
export default BeerCommentQueryResult;

View File

@@ -22,15 +22,6 @@ export default interface BeerPostQueryResult {
id: string;
username: string;
};
beerComments: {
id: string;
content: string;
createdAt: Date;
postedBy: {
id: string;
username: string;
};
}[];
createdAt: Date;
}

View File

@@ -0,0 +1,15 @@
import { BeerPost } from '@prisma/client';
type BeerRecommendationQueryResult = BeerPost & {
brewery: {
id: string;
name: string;
};
beerImages: {
id: string;
alt: string;
url: string;
}[];
};
export default BeerRecommendationQueryResult;