subman-nextjs/src/app/lib/del.ts

37 lines
757 B
TypeScript

"use server"
import { revalidatePath } from "next/cache";
import prisma from "./db";
import { redirect } from "next/navigation";
export async function deleteRecord(id: number, pathname: "/story" | "/publication" | "/submission") {
let res = {}
switch (pathname) {
case "/story":
res = await prisma.story.delete({
where: { id }
})
console.log(`deleted: ${res}`)
break;
case "/publication":
res = await prisma.pub.delete({
where: { id }
})
console.log(`deleted: ${res}`)
break;
case "/submission":
res = await prisma.sub.delete({
where: { id }
})
console.log(`deleted: ${res}`)
break;
default:
break;
}
console.log("revalidating: " + pathname)
revalidatePath(pathname)
redirect(pathname)
}