-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeletePost.ts
45 lines (43 loc) · 946 Bytes
/
deletePost.ts
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
"use server"
import { db } from "@/lib/db";
import { auth } from "../auth";
import { getUserByEmail } from "./user";
export const deletepost = async (post_id: number) => {
try {
await db.$transaction([
db.commentLike.deleteMany({
where: {
coment: {
post: {
id: post_id
}
}
}
}),
db.coment.deleteMany({
where : {
post_id
},
}),
db.postLike.deleteMany({
where: {
postId: post_id
}
}),
db.savedPost.deleteMany({
where: {
postId: post_id
}
}),
db.post.delete({
where: {
id: post_id
}
})
]);
return { success: "Post deletado com sucesso!", error: null };
} catch (error) {
console.error('Erro ao deletar post:', error);
return { success: null, error: "Erro ao deletar o post." };
}
};