23 lines
619 B
TypeScript
23 lines
619 B
TypeScript
import { Genre, Story } from "@prisma/client"
|
|
import { StoryWithGenres } from "app/story/page"
|
|
import prisma from "./db"
|
|
import { revalidatePath } from "next/cache"
|
|
import { redirect } from "next/navigation"
|
|
|
|
export async function updateStory(data: Story & { genres: number[] }) {
|
|
"use server"
|
|
const genresArray = data.genres.map((e) => { return { id: e } })
|
|
|
|
const res = await prisma.story.update({
|
|
where: { id: data.id },
|
|
data: {
|
|
title: data.title,
|
|
word_count: data.word_count,
|
|
genres: { set: genresArray }
|
|
}
|
|
})
|
|
console.log(`updated story: ${res}`)
|
|
revalidatePath("/story")
|
|
redirect("/story")
|
|
}
|