"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) { const table = tableMap[pathname] const res = await prisma[table].delete({ where: { id } }) console.log(`deleted from ${table}: ${res.id}`) console.log("revalidating: " + pathname) revalidatePath(pathname) redirect(pathname) } 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}`) }) }