Skip to content

Commit b676880

Browse files
committed
Implemented interactions deletion on deleteAnswer and deleteQuestion sevrer-actions
1 parent 2432e34 commit b676880

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

app/api/webhook/clerk/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { WebhookEvent } from "@clerk/nextjs/server";
88
import { createUser, deleteUser, updateUser } from "@/lib/actions/user.action";
99

1010
export async function POST(req: Request) {
11-
// TODO: Add your own Clerk webhook secret here
1211
// You can find this in the Clerk Dashboard -> Webhooks -> choose the webhook
1312
const WEBHOOK_SECRET = process.env.CLERK_WEBHOOK_SECRET;
1413

@@ -65,7 +64,7 @@ export async function POST(req: Request) {
6564
const mongoUser = await createUser({
6665
clerkId: id,
6766
name: `${first_name}${last_name ? ` ${last_name}` : ""}`,
68-
username: username!,
67+
username: username || "",
6968
email: email_addresses[0].email_address,
7069
picture: image_url,
7170
});

lib/actions/answer.action.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ export async function deleteAnswer(params: DeleteAnswerParams) {
9898
{ $pull: { answers: answerId } }
9999
);
100100

101-
// todo: delete all interactions related to the answer
102-
103-
// todo: decrement author's reputation by +S for deleting a answer
101+
await Interaction.deleteMany({ answer: answerId });
104102

105103
revalidatePath(path);
106104
} catch (error) {

lib/actions/question.action.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,13 @@ export async function deleteQuestion(params: DeleteQuestionParams) {
125125

126126
await Answer.deleteMany({ question: questionId });
127127

128-
// todo: delete all interactions related to the question
128+
await Interaction.deleteMany({ question: questionId });
129129

130130
await Tag.updateMany(
131131
{ questions: questionId },
132132
{ $pull: { questions: questionId } }
133133
);
134134

135-
// todo: decrement author's reputation by +S for deleting a answer
136135
await User.findByIdAndUpdate(question.author, {
137136
$inc: { reputation: -10 },
138137
});

0 commit comments

Comments
 (0)