mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Formatting changes
This commit is contained in:
@@ -2,8 +2,9 @@ import DBClient from '@/prisma/DBClient';
|
||||
import { z } from 'zod';
|
||||
import BeerCommentValidationSchema from './schema/CreateBeerCommentValidationSchema';
|
||||
|
||||
const CreateBeerCommentWithUserSchema = BeerCommentValidationSchema.extend({
|
||||
const CreateNewBeerCommentServiceSchema = BeerCommentValidationSchema.extend({
|
||||
userId: z.string().uuid(),
|
||||
beerPostId: z.string().uuid(),
|
||||
});
|
||||
|
||||
const createNewBeerComment = async ({
|
||||
@@ -11,7 +12,7 @@ const createNewBeerComment = async ({
|
||||
rating,
|
||||
beerPostId,
|
||||
userId,
|
||||
}: z.infer<typeof CreateBeerCommentWithUserSchema>) => {
|
||||
}: z.infer<typeof CreateNewBeerCommentServiceSchema>) => {
|
||||
return DBClient.instance.beerComment.create({
|
||||
data: {
|
||||
content,
|
||||
|
||||
@@ -9,27 +9,17 @@ const getAllBeerComments = async (
|
||||
const skip = (pageNum - 1) * pageSize;
|
||||
const beerComments: BeerCommentQueryResultArrayT =
|
||||
await DBClient.instance.beerComment.findMany({
|
||||
where: {
|
||||
beerPostId: id,
|
||||
},
|
||||
skip,
|
||||
take: pageSize,
|
||||
where: { beerPostId: id },
|
||||
select: {
|
||||
id: true,
|
||||
content: true,
|
||||
rating: true,
|
||||
createdAt: true,
|
||||
postedBy: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
createdAt: true,
|
||||
},
|
||||
},
|
||||
postedBy: { select: { id: true, username: true, createdAt: true } },
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
skip,
|
||||
take: pageSize,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
return beerComments;
|
||||
};
|
||||
|
||||
@@ -10,7 +10,6 @@ const BeerCommentValidationSchema = z.object({
|
||||
.int()
|
||||
.min(1, { message: 'Rating must be greater than 1.' })
|
||||
.max(5, { message: 'Rating must be less than 5.' }),
|
||||
beerPostId: z.string().uuid({ message: 'Beer post ID must be a valid UUID.' }),
|
||||
});
|
||||
|
||||
export default BeerCommentValidationSchema;
|
||||
|
||||
@@ -10,36 +10,14 @@ const getAllBeerPosts = async (pageNum: number, pageSize: number) => {
|
||||
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: {
|
||||
path: true,
|
||||
caption: true,
|
||||
id: true,
|
||||
alt: 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: pageSize,
|
||||
skip,
|
||||
|
||||
@@ -6,56 +6,18 @@ const prisma = DBClient.instance;
|
||||
const getBeerPostById = async (id: string) => {
|
||||
const beerPost: BeerPostQueryResult | null = await prisma.beerPost.findFirst({
|
||||
select: {
|
||||
beerComments: {
|
||||
select: {
|
||||
id: true,
|
||||
content: true,
|
||||
createdAt: true,
|
||||
postedBy: {
|
||||
select: {
|
||||
username: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
rating: true,
|
||||
},
|
||||
},
|
||||
id: true,
|
||||
name: true,
|
||||
brewery: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
ibu: true,
|
||||
abv: true,
|
||||
type: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
beerImages: {
|
||||
select: {
|
||||
alt: true,
|
||||
path: true,
|
||||
caption: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
createdAt: true,
|
||||
description: true,
|
||||
postedBy: {
|
||||
select: {
|
||||
username: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
id,
|
||||
postedBy: { select: { username: true, id: true } },
|
||||
brewery: { select: { name: true, id: true } },
|
||||
type: { select: { name: true, id: true } },
|
||||
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
|
||||
},
|
||||
where: { id },
|
||||
});
|
||||
|
||||
return beerPost;
|
||||
|
||||
Reference in New Issue
Block a user