From 9731f3c96c710a36405d422f398c6e917aee5a6e Mon Sep 17 00:00:00 2001 From: Wesley Souza | Neo Date: Tue, 26 Nov 2024 00:33:08 -0300 Subject: [PATCH] feat: :sparkles: add action to delete transactions --- app/_actions/delete-transactions/index.ts | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/_actions/delete-transactions/index.ts diff --git a/app/_actions/delete-transactions/index.ts b/app/_actions/delete-transactions/index.ts new file mode 100644 index 0000000..92501c4 --- /dev/null +++ b/app/_actions/delete-transactions/index.ts @@ -0,0 +1,29 @@ +"use server"; + +import { db } from "@/app/_lib/prisma"; +import { auth } from "@clerk/nextjs/server"; +import { revalidatePath } from "next/cache"; + +interface IDeleteTransactions { + transactionId: string; +} + +export const deleteTransaction = async ({ + transactionId, +}: IDeleteTransactions) => { + const { userId } = await auth(); + + if (!userId) { + throw new Error("", { + cause: "You need log-in account to delete transactions.", + }); + } + + await db.transactions.delete({ + where: { + id: transactionId, + userId, + }, + }); + revalidatePath("/transactions"); +};