mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Update: all queries involving image now use ImageQueryValidationSchema
This commit is contained in:
27
src/components/Account/UserAvatar.tsx
Normal file
27
src/components/Account/UserAvatar.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
import Image from 'next/image';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import GetUserSchema from '@/services/User/schema/GetUserSchema';
|
||||||
|
|
||||||
|
interface UserAvatarProps {
|
||||||
|
user: {
|
||||||
|
username: z.infer<typeof GetUserSchema>['username'];
|
||||||
|
userAvatar: z.infer<typeof GetUserSchema>['userAvatar'];
|
||||||
|
id: z.infer<typeof GetUserSchema>['id'];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const UserAvatar: FC<UserAvatarProps> = ({ user }) => {
|
||||||
|
const { userAvatar } = user;
|
||||||
|
return !userAvatar ? null : (
|
||||||
|
<Image
|
||||||
|
src={userAvatar.path}
|
||||||
|
alt="user avatar"
|
||||||
|
width={1000}
|
||||||
|
height={1000}
|
||||||
|
className="h-full w-full"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UserAvatar;
|
||||||
@@ -4,9 +4,9 @@ import { FC, useState } from 'react';
|
|||||||
import { useInView } from 'react-intersection-observer';
|
import { useInView } from 'react-intersection-observer';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import CreateCommentValidationSchema from '@/services/schema/CommentSchema/CreateCommentValidationSchema';
|
import CreateCommentValidationSchema from '@/services/schema/CommentSchema/CreateCommentValidationSchema';
|
||||||
import Image from 'next/image';
|
|
||||||
import CommentContentBody from './CommentContentBody';
|
import CommentContentBody from './CommentContentBody';
|
||||||
import EditCommentBody from './EditCommentBody';
|
import EditCommentBody from './EditCommentBody';
|
||||||
|
import UserAvatar from '../Account/UserAvatar';
|
||||||
|
|
||||||
interface CommentCardProps {
|
interface CommentCardProps {
|
||||||
comment: z.infer<typeof CommentQueryResult>;
|
comment: z.infer<typeof CommentQueryResult>;
|
||||||
@@ -28,20 +28,11 @@ const CommentCardBody: FC<CommentCardProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [inEditMode, setInEditMode] = useState(false);
|
const [inEditMode, setInEditMode] = useState(false);
|
||||||
|
|
||||||
const { userAvatar } = comment.postedBy;
|
|
||||||
return (
|
return (
|
||||||
<div ref={ref} className="flex">
|
<div ref={ref} className="flex">
|
||||||
<div className="w-[12%] py-4 justify-center">
|
<div className="w-[12%] py-4 justify-center">
|
||||||
<div className="px-1 mask mask-circle">
|
<div className="px-1 mask mask-circle">
|
||||||
{!userAvatar ? null : (
|
<UserAvatar user={comment.postedBy} />
|
||||||
<Image
|
|
||||||
src={userAvatar.path}
|
|
||||||
alt="user avatar"
|
|
||||||
width={1000}
|
|
||||||
height={1000}
|
|
||||||
className="h-full w-full"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,16 @@ const search = async (req: SearchAPIRequest, res: NextApiResponse) => {
|
|||||||
postedBy: { select: { username: true, id: true } },
|
postedBy: { select: { username: true, id: true } },
|
||||||
brewery: { select: { name: true, id: true } },
|
brewery: { select: { name: true, id: true } },
|
||||||
style: { select: { name: true, id: true, description: true } },
|
style: { select: { name: true, id: true, description: true } },
|
||||||
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
OR: [
|
OR: [
|
||||||
|
|||||||
@@ -34,7 +34,16 @@ const getAllBeersByBrewery = async (
|
|||||||
postedBy: { select: { username: true, id: true } },
|
postedBy: { select: { username: true, id: true } },
|
||||||
brewery: { select: { name: true, id: true } },
|
brewery: { select: { name: true, id: true } },
|
||||||
style: { select: { name: true, id: true, description: true } },
|
style: { select: { name: true, id: true, description: true } },
|
||||||
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,16 @@ const createNewBeerPost = ({
|
|||||||
ibu: true,
|
ibu: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
brewery: { select: { id: true, name: true } },
|
brewery: { select: { id: true, name: true } },
|
||||||
style: { select: { id: true, name: true, description: true } },
|
style: { select: { id: true, name: true, description: true } },
|
||||||
postedBy: { select: { id: true, username: true } },
|
postedBy: { select: { id: true, username: true } },
|
||||||
|
|||||||
@@ -19,7 +19,16 @@ const deleteBeerPostById = ({
|
|||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
style: { select: { id: true, name: true, description: true } },
|
style: { select: { id: true, name: true, description: true } },
|
||||||
postedBy: { select: { id: true, username: true } },
|
postedBy: { select: { id: true, username: true } },
|
||||||
brewery: { select: { id: true, name: true } },
|
brewery: { select: { id: true, name: true } },
|
||||||
|
|||||||
@@ -25,7 +25,16 @@ const editBeerPostById = ({
|
|||||||
ibu: true,
|
ibu: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
brewery: { select: { id: true, name: true } },
|
brewery: { select: { id: true, name: true } },
|
||||||
style: { select: { id: true, name: true, description: true } },
|
style: { select: { id: true, name: true, description: true } },
|
||||||
postedBy: { select: { id: true, username: true } },
|
postedBy: { select: { id: true, username: true } },
|
||||||
|
|||||||
@@ -25,7 +25,16 @@ const getAllBeerPosts = ({
|
|||||||
style: { select: { name: true, id: true, description: true } },
|
style: { select: { name: true, id: true, description: true } },
|
||||||
brewery: { select: { name: true, id: true } },
|
brewery: { select: { name: true, id: true } },
|
||||||
postedBy: { select: { id: true, username: true } },
|
postedBy: { select: { id: true, username: true } },
|
||||||
beerImages: { select: { path: true, caption: true, id: true, alt: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
skip: (pageNum - 1) * pageSize,
|
skip: (pageNum - 1) * pageSize,
|
||||||
|
|||||||
@@ -19,7 +19,16 @@ const getBeerPostById = async (
|
|||||||
postedBy: { select: { username: true, id: true } },
|
postedBy: { select: { username: true, id: true } },
|
||||||
brewery: { select: { name: true, id: true } },
|
brewery: { select: { name: true, id: true } },
|
||||||
style: { select: { name: true, id: true, description: true } },
|
style: { select: { name: true, id: true, description: true } },
|
||||||
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,7 +28,16 @@ const getBeerPostsByBeerStyleId = async ({
|
|||||||
postedBy: { select: { username: true, id: true } },
|
postedBy: { select: { username: true, id: true } },
|
||||||
brewery: { select: { name: true, id: true } },
|
brewery: { select: { name: true, id: true } },
|
||||||
style: { select: { name: true, id: true, description: true } },
|
style: { select: { name: true, id: true, description: true } },
|
||||||
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,16 @@ const getBeerPostsByBeerStyleId = async ({
|
|||||||
postedBy: { select: { username: true, id: true } },
|
postedBy: { select: { username: true, id: true } },
|
||||||
brewery: { select: { name: true, id: true } },
|
brewery: { select: { name: true, id: true } },
|
||||||
style: { select: { name: true, id: true, description: true } },
|
style: { select: { name: true, id: true, description: true } },
|
||||||
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,16 @@ const getBeerRecommendations = async ({
|
|||||||
style: { select: { name: true, id: true, description: true } },
|
style: { select: { name: true, id: true, description: true } },
|
||||||
brewery: { select: { name: true, id: true } },
|
brewery: { select: { name: true, id: true } },
|
||||||
postedBy: { select: { id: true, username: true } },
|
postedBy: { select: { id: true, username: true } },
|
||||||
beerImages: { select: { path: true, caption: true, id: true, alt: true } },
|
beerImages: {
|
||||||
|
select: {
|
||||||
|
alt: true,
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
take,
|
take,
|
||||||
skip,
|
skip,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import ImageQueryValidationSchema from '@/services/schema/ImageSchema/ImageQueryValidationSchema';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const BeerPostQueryResult = z.object({
|
const BeerPostQueryResult = z.object({
|
||||||
@@ -5,9 +6,7 @@ const BeerPostQueryResult = z.object({
|
|||||||
name: z.string(),
|
name: z.string(),
|
||||||
brewery: z.object({ id: z.string(), name: z.string() }),
|
brewery: z.object({ id: z.string(), name: z.string() }),
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
beerImages: z.array(
|
beerImages: z.array(ImageQueryValidationSchema),
|
||||||
z.object({ path: z.string(), caption: z.string(), id: z.string(), alt: z.string() }),
|
|
||||||
),
|
|
||||||
ibu: z.number(),
|
ibu: z.number(),
|
||||||
abv: z.number(),
|
abv: z.number(),
|
||||||
style: z.object({ id: z.string(), name: z.string(), description: z.string() }),
|
style: z.object({ id: z.string(), name: z.string(), description: z.string() }),
|
||||||
|
|||||||
@@ -37,7 +37,16 @@ const createNewBreweryPost = async ({
|
|||||||
createdAt: true,
|
createdAt: true,
|
||||||
dateEstablished: true,
|
dateEstablished: true,
|
||||||
postedBy: { select: { id: true, username: true } },
|
postedBy: { select: { id: true, username: true } },
|
||||||
breweryImages: { select: { path: true, caption: true, id: true, alt: true } },
|
breweryImages: {
|
||||||
|
select: {
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
alt: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
location: {
|
location: {
|
||||||
select: {
|
select: {
|
||||||
city: true,
|
city: true,
|
||||||
|
|||||||
@@ -29,7 +29,16 @@ const getAllBreweryPosts = async ({
|
|||||||
description: true,
|
description: true,
|
||||||
name: true,
|
name: true,
|
||||||
postedBy: { select: { username: true, id: true } },
|
postedBy: { select: { username: true, id: true } },
|
||||||
breweryImages: { select: { path: true, caption: true, id: true, alt: true } },
|
breweryImages: {
|
||||||
|
select: {
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
alt: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
dateEstablished: true,
|
dateEstablished: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,7 +19,16 @@ const getBreweryPostById = async (id: string) => {
|
|||||||
},
|
},
|
||||||
description: true,
|
description: true,
|
||||||
name: true,
|
name: true,
|
||||||
breweryImages: { select: { path: true, caption: true, id: true, alt: true } },
|
breweryImages: {
|
||||||
|
select: {
|
||||||
|
path: true,
|
||||||
|
caption: true,
|
||||||
|
id: true,
|
||||||
|
alt: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
postedBy: { select: { username: true, id: true } },
|
postedBy: { select: { username: true, id: true } },
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
dateEstablished: true,
|
dateEstablished: true,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import ImageQueryValidationSchema from '@/services/schema/ImageSchema/ImageQueryValidationSchema';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const BreweryPostQueryResult = z.object({
|
const BreweryPostQueryResult = z.object({
|
||||||
@@ -12,9 +13,7 @@ const BreweryPostQueryResult = z.object({
|
|||||||
stateOrProvince: z.string().nullable(),
|
stateOrProvince: z.string().nullable(),
|
||||||
}),
|
}),
|
||||||
postedBy: z.object({ id: z.string(), username: z.string() }),
|
postedBy: z.object({ id: z.string(), username: z.string() }),
|
||||||
breweryImages: z.array(
|
breweryImages: z.array(ImageQueryValidationSchema),
|
||||||
z.object({ path: z.string(), caption: z.string(), id: z.string(), alt: z.string() }),
|
|
||||||
),
|
|
||||||
createdAt: z.coerce.date(),
|
createdAt: z.coerce.date(),
|
||||||
dateEstablished: z.coerce.date(),
|
dateEstablished: z.coerce.date(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import ImageQueryValidationSchema from '@/services/schema/ImageSchema/ImageQueryValidationSchema';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const GetUserSchema = z.object({
|
const GetUserSchema = z.object({
|
||||||
@@ -12,16 +13,7 @@ const GetUserSchema = z.object({
|
|||||||
accountIsVerified: z.boolean(),
|
accountIsVerified: z.boolean(),
|
||||||
role: z.enum(['USER', 'ADMIN']),
|
role: z.enum(['USER', 'ADMIN']),
|
||||||
bio: z.string().nullable(),
|
bio: z.string().nullable(),
|
||||||
userAvatar: z
|
userAvatar: ImageQueryValidationSchema.nullable(),
|
||||||
.object({
|
|
||||||
id: z.string().cuid(),
|
|
||||||
path: z.string().url(),
|
|
||||||
alt: z.string(),
|
|
||||||
caption: z.string(),
|
|
||||||
createdAt: z.coerce.date(),
|
|
||||||
updatedAt: z.coerce.date().nullable(),
|
|
||||||
})
|
|
||||||
.nullable(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default GetUserSchema;
|
export default GetUserSchema;
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import ImageQueryValidationSchema from '../ImageSchema/ImageQueryValidationSchema';
|
||||||
|
|
||||||
const CommentQueryResult = z.object({
|
const CommentQueryResult = z.object({
|
||||||
id: z.string().cuid(),
|
id: z.string().cuid(),
|
||||||
content: z.string().min(1).max(500),
|
content: z.string().min(1).max(500),
|
||||||
rating: z.number().int().min(1).max(5),
|
rating: z.number().int().min(1).max(5),
|
||||||
createdAt: z.coerce.date(),
|
createdAt: z.coerce.date(),
|
||||||
|
updatedAt: z.coerce.date().nullable(),
|
||||||
postedBy: z.object({
|
postedBy: z.object({
|
||||||
id: z.string().cuid(),
|
id: z.string().cuid(),
|
||||||
username: z.string().min(1).max(50),
|
username: z.string().min(1).max(50),
|
||||||
userAvatar: z
|
userAvatar: ImageQueryValidationSchema.nullable(),
|
||||||
.object({
|
|
||||||
id: z.string().cuid(),
|
|
||||||
path: z.string().url(),
|
|
||||||
alt: z.string().min(1).max(50),
|
|
||||||
caption: z.string().min(1).max(50),
|
|
||||||
})
|
|
||||||
.nullable(),
|
|
||||||
}),
|
}),
|
||||||
updatedAt: z.coerce.date().nullable(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default CommentQueryResult;
|
export default CommentQueryResult;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
const ImageQueryValidationSchema = z.object({
|
||||||
|
id: z.string().cuid(),
|
||||||
|
path: z.string().url(),
|
||||||
|
alt: z.string(),
|
||||||
|
caption: z.string(),
|
||||||
|
createdAt: z.coerce.date(),
|
||||||
|
updatedAt: z.coerce.date().nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ImageQueryValidationSchema;
|
||||||
Reference in New Issue
Block a user