"use server" import { revalidatePath } from "next/cache"; import prisma from "./db"; import { redirect } from "next/navigation"; import { Pathname } from "app/types"; const tableMap = { "/story": "story", "/publication": "pub", "/submission": "sub" } export async function deleteRecord(id: number, pathname: Pathname): Promise { const table = tableMap[pathname] try { const res = await prisma[table].delete({ where: { id } }) console.log(`deleted from ${table}: ${res.id}`) revalidatePath(pathname) return true } catch (error) { console.error(error) return undefined } } export async function deleteRecords(ids: number[], pathname: "/story" | "/publication" | "/submission"): Promise { try { const table = tableMap[pathname] ids.forEach(async (id) => { const res = await prisma[table].delete({ where: { id } }) console.log(`deleted from ${table}: ${res.id}`) }) revalidatePath(pathname) return true } catch (error) { console.error(error) return undefined } }