forked from gss-patricia/code-connect-artigo
/
index.js
64 lines (55 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use server";
import { revalidatePath } from "next/cache";
import db from "../../prisma/db";
export async function incrementThumbsUp(post) {
debugger;
await db.post.update({
where: {
id: post.id,
},
data: {
likes: {
increment: 1,
},
},
});
revalidatePath("/");
revalidatePath(`/${post.slug}`);
}
export async function postComment(post, formData) {
const author = await db.user.findFirst({
where: {
username: "anabeatriz_dev",
},
});
await db.comment.create({
data: {
text: formData.get("text"),
authorId: author.id,
postId: post.id,
},
});
revalidatePath("/");
revalidatePath(`/${post.slug}`);
}
export async function postReply(parent, formData) {
const author = await db.user.findFirst({
where: {
username: "anabeatriz_dev",
},
});
const post = await db.post.findFirst({
where: {
id: parent.postId,
},
});
await db.comment.create({
data: {
text: formData.get("text"),
authorId: author.id,
postId: post.id,
parentId: parent.parentId ?? parent.id,
},
});
revalidatePath(`/${post.slug}`);
}