Skip to content

Commit

Permalink
new note created in database
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnmclean committed Dec 26, 2024
1 parent 99d8162 commit 5d58d60
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions apps/sovoli.com/src/app/(dashboard)/new/actions/newNoteAction.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"use server";

import { unauthorized } from "next/navigation";
import { redirect, unauthorized } from "next/navigation";
import { withZod } from "@rvf/zod";
import { auth } from "@sovoli/auth";
import { db, schema } from "@sovoli/db";

import { slugify } from "~/utils/slugify";
import { formNewNoteSchema } from "./schemas";

export type State = {
Expand Down Expand Up @@ -33,7 +35,24 @@ export async function newNoteAction(
};
}

console.log(result.data);
const [createdKnowledge] = await db
.insert(schema.Knowledge)
.values({
userId: session.userId,
title: result.data.title,
description: result.data.description,
slug: result.data.title ? slugify(result.data.title) : "",
content: result.data.content,
isOrigin: true,
})
.returning();

if (!createdKnowledge) {
return {
status: "error",
message: "Failed to create knowledge",
};
}

throw new Error("Not implemented");
redirect(`/${session.user?.username}/${createdKnowledge.slug}`);
}

0 comments on commit 5d58d60

Please sign in to comment.