extrapolate create function
This commit is contained in:
parent
9c9b010dc1
commit
483b9d987a
|
@ -0,0 +1,29 @@
|
||||||
|
"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")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue