extrapolate create function

This commit is contained in:
andrzej 2024-06-26 18:18:44 +02:00
parent 191457d6c1
commit 788051fa10
1 changed files with 29 additions and 0 deletions

29
src/app/lib/create.ts Normal file
View File

@ -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")
}