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-27 14:49:56 +00:00
|
|
|
import { Pathname } from "app/types";
|
2024-06-19 16:01:42 +00:00
|
|
|
|
2024-06-27 14:08:03 +00:00
|
|
|
const tableMap = {
|
|
|
|
"/story": "story",
|
|
|
|
"/publication": "pub",
|
|
|
|
"/submission": "sub"
|
|
|
|
}
|
|
|
|
|
2024-06-27 14:49:56 +00:00
|
|
|
export async function deleteRecord(id: number, pathname: Pathname) {
|
2024-06-27 14:08:03 +00:00
|
|
|
const table = tableMap[pathname]
|
|
|
|
const res = await prisma[table].delete({ where: { id } })
|
|
|
|
console.log(`deleted from ${table}: ${res.id}`)
|
2024-06-27 10:44:31 +00:00
|
|
|
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 14:08:03 +00:00
|
|
|
export async function deleteRecords(ids: number[], pathname: "/story" | "/publication" | "/submission") {
|
|
|
|
const table = tableMap[pathname]
|
|
|
|
ids.forEach(async (id) => {
|
|
|
|
const res = await prisma.story.delete({
|
|
|
|
where: { id }
|
|
|
|
})
|
|
|
|
console.log(`deleted from ${table}: ${res.id}`)
|
|
|
|
})
|
2024-06-27 10:44:31 +00:00
|
|
|
|
|
|
|
|
2024-06-27 14:08:03 +00:00
|
|
|
}
|
|
|
|
|