Finished webhook handler for user.deleted
This commit is contained in:
parent
37fc8732dd
commit
9b07973c01
1 changed files with 22 additions and 2 deletions
|
@ -1,4 +1,7 @@
|
|||
import { eq } from "drizzle-orm";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { db } from "~/server/db";
|
||||
import { logs, rooms, votes } from "~/server/schema";
|
||||
import { validateApiKey } from "~/server/unkey";
|
||||
|
||||
export default async function handler(
|
||||
|
@ -20,7 +23,24 @@ export default async function handler(
|
|||
res.status(403).json({ error: "UNAUTHORIZED" });
|
||||
}
|
||||
|
||||
console.log(req.body);
|
||||
const requestBody = req.body as {
|
||||
data: {
|
||||
deleted: string;
|
||||
id: string;
|
||||
object: string;
|
||||
};
|
||||
object: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
res.status(200).json({ result: "AUTHORIZED" });
|
||||
const deletedRoom = await db
|
||||
.delete(rooms)
|
||||
.where(eq(rooms.userId, requestBody.data.id));
|
||||
|
||||
if (deletedRoom.rowsAffected > 0) {
|
||||
await db.delete(logs).where(eq(logs.userId, requestBody.data.id));
|
||||
await db.delete(votes).where(eq(votes.userId, requestBody.data.id));
|
||||
}
|
||||
|
||||
res.status(200).json({ result: "USER DELETED" });
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue