Add some validation refactors and fixes
This commit is contained in:
parent
e7bfd1f2d5
commit
364d3a1917
|
@ -23,7 +23,7 @@ export function Poster({
|
|||
return style === "compact" ? (
|
||||
<div>
|
||||
<img
|
||||
className={`peer/image rounded-full border w-6`}
|
||||
className={`peer/image rounded-full border w-6 h-6`}
|
||||
src={
|
||||
pfp
|
||||
? `
|
||||
|
@ -39,7 +39,7 @@ export function Poster({
|
|||
) : (
|
||||
<div className={`flex break-all items-center gap-3 ${className}`}>
|
||||
<img
|
||||
className="rounded-full border w-12"
|
||||
className="rounded-full border w-12 h-12"
|
||||
src={
|
||||
pfp
|
||||
? `
|
||||
|
|
|
@ -13,23 +13,32 @@ export async function likePost(postId: number, id: number) {
|
|||
};
|
||||
|
||||
const post = await getPostById(postId);
|
||||
|
||||
if (!post) {
|
||||
errors.postId = "No post with that id";
|
||||
}
|
||||
|
||||
const like = await prisma.like.findFirst({
|
||||
where: {
|
||||
userId: id,
|
||||
postId: postId,
|
||||
},
|
||||
});
|
||||
if (like) {
|
||||
errors.like = "You have already liked that post";
|
||||
}
|
||||
|
||||
if (Object.values(errors).some(Boolean)) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
const like = await prisma.like.create({
|
||||
const likeQ = await prisma.like.create({
|
||||
data: {
|
||||
postId: postId,
|
||||
userId: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!like) {
|
||||
if (!likeQ) {
|
||||
errors.like = "Something went wrong liking the post";
|
||||
return errors;
|
||||
}
|
||||
|
@ -55,7 +64,7 @@ export async function unLikePost(postId: number, id: number) {
|
|||
},
|
||||
});
|
||||
if (!like) {
|
||||
errors.like = "Repost doesn't exist";
|
||||
errors.like = "Like doesn't exist";
|
||||
}
|
||||
|
||||
if (Object.values(errors).some(Boolean)) {
|
||||
|
|
|
@ -10,18 +10,29 @@ export async function repost(postId: number, id: number) {
|
|||
errors.repost = "Post doesn't exist";
|
||||
}
|
||||
|
||||
const repost = await prisma.repost.findFirst({
|
||||
where: {
|
||||
postId: postId,
|
||||
userId: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (repost) {
|
||||
errors.repost = "You have already reposted that post";
|
||||
}
|
||||
|
||||
if (Object.values(errors).some(Boolean)) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
const repost = await prisma.repost.create({
|
||||
const repostQ = await prisma.repost.create({
|
||||
data: {
|
||||
userId: id,
|
||||
postId: postId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!repost) {
|
||||
if (!repostQ) {
|
||||
errors.repost = "Something went wrong";
|
||||
}
|
||||
|
||||
|
|
|
@ -196,14 +196,14 @@ export default function Settings() {
|
|||
<input type="hidden" name="intent" value="password" />
|
||||
<FormLabel>
|
||||
<Text>Old password</Text>{" "}
|
||||
<FormInput type="text" name="opassword" />{" "}
|
||||
<FormInput type="password" name="opassword" />{" "}
|
||||
<Text type="error">
|
||||
{data?.errors?.opassword ? data.errors.opassword : ""}
|
||||
</Text>
|
||||
</FormLabel>
|
||||
<FormLabel>
|
||||
<Text>New password</Text>{" "}
|
||||
<FormInput type="text" name="npassword" />{" "}
|
||||
<FormInput type="password" name="npassword" />{" "}
|
||||
<Text type="error">
|
||||
{data?.errors?.npassword ? data.errors.npassword : ""}
|
||||
</Text>
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue