Skip to content

Commit

Permalink
feat: ✨ add action to delete transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
neopromic committed Nov 26, 2024
1 parent 9e606af commit 9731f3c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/_actions/delete-transactions/index.ts
Original file line number Diff line number Diff line change
@@ -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");
};

0 comments on commit 9731f3c

Please sign in to comment.