mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
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:
37
services/BeerPost/getAllBeerComments.ts
Normal file
37
services/BeerPost/getAllBeerComments.ts
Normal 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;
|
||||
@@ -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,
|
||||
|
||||
@@ -17,6 +17,7 @@ const getBeerPostById = async (id: string) => {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
rating: true,
|
||||
},
|
||||
},
|
||||
id: true,
|
||||
|
||||
31
services/BeerPost/getBeerRecommendations.ts
Normal file
31
services/BeerPost/getBeerRecommendations.ts
Normal 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;
|
||||
13
services/BeerPost/types/BeerCommentQueryResult.ts
Normal file
13
services/BeerPost/types/BeerCommentQueryResult.ts
Normal 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;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
15
services/BeerPost/types/BeerReccomendationQueryResult.ts
Normal file
15
services/BeerPost/types/BeerReccomendationQueryResult.ts
Normal 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;
|
||||
Reference in New Issue
Block a user