2024-06-19 16:01:42 +00:00
|
|
|
"use server"
|
2024-06-19 17:46:30 +00:00
|
|
|
import { revalidatePath } from "next/cache";
|
2024-06-19 16:01:42 +00:00
|
|
|
import prisma from "./db";
|
2024-06-19 17:46:30 +00:00
|
|
|
import { redirect } from "next/navigation";
|
2024-06-19 16:01:42 +00:00
|
|
|
|
2024-06-27 10:44:31 +00:00
|
|
|
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)
|
2024-06-20 08:35:25 +00:00
|
|
|
}
|
2024-06-20 09:39:35 +00:00
|
|
|
|
2024-06-27 10:44:31 +00:00
|
|
|
|
|
|
|
|