30 lines
623 B
TypeScript
30 lines
623 B
TypeScript
|
"use server"
|
||
|
import { Genre } from "@prisma/client"
|
||
|
import prisma from "./db"
|
||
|
import { revalidatePath } from "next/cache"
|
||
|
import { redirect } from "next/navigation"
|
||
|
|
||
|
export async function createStory(data) {
|
||
|
"use server"
|
||
|
const genresArray = data.genres.map((e: Genre) => { return { id: e } })
|
||
|
const res = await prisma.story.create({
|
||
|
data: {
|
||
|
title: data.title,
|
||
|
word_count: data.word_count,
|
||
|
}
|
||
|
})
|
||
|
console.log(res)
|
||
|
const genresRes = await prisma.story.update({
|
||
|
where: { id: res.id },
|
||
|
data: {
|
||
|
genres: { set: genresArray }
|
||
|
}
|
||
|
})
|
||
|
console.log(genresRes)
|
||
|
revalidatePath("/story")
|
||
|
redirect("/story")
|
||
|
}
|
||
|
|
||
|
|
||
|
|