65 lines
1.1 KiB
TypeScript
65 lines
1.1 KiB
TypeScript
import { prisma } from "~/utils/prisma.server";
|
|
import { getPostById } from "./post.server";
|
|
|
|
export async function repost(postId: number, id: number) {
|
|
const errors = {};
|
|
|
|
const post = await getPostById(postId);
|
|
|
|
if (!post) {
|
|
errors.repost = "Post doesn't exist";
|
|
}
|
|
|
|
if (Object.values(errors).some(Boolean)) {
|
|
return errors;
|
|
}
|
|
|
|
const repost = await prisma.user.update({
|
|
where: {
|
|
id: id,
|
|
},
|
|
data: {
|
|
reposts: {
|
|
connect: { id: postId },
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!repost) {
|
|
errors.repost = "Something went wrong";
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
export async function unRepost(postId: number, id: number) {
|
|
const errors = {};
|
|
|
|
const post = await getPostById(postId);
|
|
|
|
if (!post) {
|
|
errors.repost = "Post doesn't exist";
|
|
}
|
|
|
|
if (Object.values(errors).some(Boolean)) {
|
|
return errors;
|
|
}
|
|
|
|
const repost = await prisma.user.update({
|
|
where: {
|
|
id: id,
|
|
},
|
|
data: {
|
|
reposts: {
|
|
disconnect: { id: postId },
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!repost) {
|
|
errors.repost = "Something went wrong";
|
|
}
|
|
|
|
return errors;
|
|
}
|