Skip to content

Commit

Permalink
Feature/ Add series to link related articles
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerCreaky committed Nov 18, 2024
1 parent c839c94 commit 454067f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
8 changes: 7 additions & 1 deletion app/(editor)/create/[[...paramsArr]]/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { uploadFile } from "@/utils/s3helpers";
import { getUploadUrl } from "@/app/actions/getUploadUrl";
import EditorNav from "./navigation";
import { type Session } from "next-auth";
import { FormDataSchema } from "@/schema/post";

const Create = ({ session }: { session: Session | null }) => {
const params = useParams();
Expand Down Expand Up @@ -213,12 +214,17 @@ const Create = ({ session }: { session: Session | null }) => {

const getFormData = () => {
const data = getValues();

const sanitizedSeriesName = FormDataSchema.parse({
seriesName: data.seriesName,
});

const formData = {
...data,
tags,
canonicalUrl: data.canonicalUrl || undefined,
excerpt: data.excerpt || removeMarkdown(data.body, {}).substring(0, 155),
seriesName: data.seriesName || undefined
...sanitizedSeriesName
};
return formData;
};
Expand Down
17 changes: 1 addition & 16 deletions drizzle/0000_initial_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ CREATE TABLE IF NOT EXISTS "Post" (
"updatedAt" timestamp(3) with time zone NOT NULL,
"slug" text NOT NULL,
"userId" text NOT NULL,
"showComments" boolean DEFAULT true NOT NULL,
"seriesId" INTEGER
"showComments" boolean DEFAULT true NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "PostTag" (
Expand Down Expand Up @@ -184,14 +183,6 @@ CREATE TABLE IF NOT EXISTS "Membership" (
"createdAt" timestamp(3) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Series" (
"id" SERIAL PRIMARY KEY,
"name" TEXT NOT NULL,
"userId" text NOT NULL,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL
);
--> statement-breakpoint

CREATE UNIQUE INDEX IF NOT EXISTS "Post_id_key" ON "Post" ("id");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "Post_slug_key" ON "Post" ("slug");--> statement-breakpoint
Expand All @@ -218,12 +209,6 @@ EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Post" ADD CONSTRAINT "Post_seriesId_fkey" FOREIGN KEY ("seriesId") REFERENCES "public"."Series" ("id") ON DELETE SET NULL;
EXCEPTION
WHEN duplicate_object THEN null;
END $$
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Post" ADD CONSTRAINT "Post_userId_User_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
Expand Down
17 changes: 17 additions & 0 deletions drizzle/0011_add_series.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Series" (
"id" SERIAL PRIMARY KEY,
"name" TEXT NOT NULL,
"userId" text NOT NULL,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL
);
-->statement-breakpoint

ALTER TABLE "Post" ADD COLUMN "seriesId" INTEGER;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Post" ADD CONSTRAINT "Post_seriesId_fkey" FOREIGN KEY ("seriesId") REFERENCES "public"."Series" ("id") ON DELETE SET NULL;
EXCEPTION
WHEN duplicate_object THEN null;
END $$
4 changes: 4 additions & 0 deletions schema/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export const GetPostsSchema = z.object({
tag: z.string().nullish(),
});

export const FormDataSchema = z.object({
seriesName: z.string().trim().optional()
})

export type SavePostInput = z.TypeOf<typeof SavePostSchema>;
export type ConfirmPostInput = z.TypeOf<typeof ConfirmPostSchema>;

Expand Down

0 comments on commit 454067f

Please sign in to comment.