Skip to content

Commit 454067f

Browse files
committed
Feature/ Add series to link related articles
1 parent c839c94 commit 454067f

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

app/(editor)/create/[[...paramsArr]]/_client.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { uploadFile } from "@/utils/s3helpers";
3737
import { getUploadUrl } from "@/app/actions/getUploadUrl";
3838
import EditorNav from "./navigation";
3939
import { type Session } from "next-auth";
40+
import { FormDataSchema } from "@/schema/post";
4041

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

214215
const getFormData = () => {
215216
const data = getValues();
217+
218+
const sanitizedSeriesName = FormDataSchema.parse({
219+
seriesName: data.seriesName,
220+
});
221+
216222
const formData = {
217223
...data,
218224
tags,
219225
canonicalUrl: data.canonicalUrl || undefined,
220226
excerpt: data.excerpt || removeMarkdown(data.body, {}).substring(0, 155),
221-
seriesName: data.seriesName || undefined
227+
...sanitizedSeriesName
222228
};
223229
return formData;
224230
};

drizzle/0000_initial_schema.sql

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ CREATE TABLE IF NOT EXISTS "Post" (
2121
"updatedAt" timestamp(3) with time zone NOT NULL,
2222
"slug" text NOT NULL,
2323
"userId" text NOT NULL,
24-
"showComments" boolean DEFAULT true NOT NULL,
25-
"seriesId" INTEGER
24+
"showComments" boolean DEFAULT true NOT NULL
2625
);
2726
--> statement-breakpoint
2827
CREATE TABLE IF NOT EXISTS "PostTag" (
@@ -184,14 +183,6 @@ CREATE TABLE IF NOT EXISTS "Membership" (
184183
"createdAt" timestamp(3) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
185184
);
186185
--> statement-breakpoint
187-
CREATE TABLE IF NOT EXISTS "Series" (
188-
"id" SERIAL PRIMARY KEY,
189-
"name" TEXT NOT NULL,
190-
"userId" text NOT NULL,
191-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
192-
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL
193-
);
194-
--> statement-breakpoint
195186

196187
CREATE UNIQUE INDEX IF NOT EXISTS "Post_id_key" ON "Post" ("id");--> statement-breakpoint
197188
CREATE UNIQUE INDEX IF NOT EXISTS "Post_slug_key" ON "Post" ("slug");--> statement-breakpoint
@@ -218,12 +209,6 @@ EXCEPTION
218209
WHEN duplicate_object THEN null;
219210
END $$;
220211
--> statement-breakpoint
221-
DO $$ BEGIN
222-
ALTER TABLE "Post" ADD CONSTRAINT "Post_seriesId_fkey" FOREIGN KEY ("seriesId") REFERENCES "public"."Series" ("id") ON DELETE SET NULL;
223-
EXCEPTION
224-
WHEN duplicate_object THEN null;
225-
END $$
226-
--> statement-breakpoint
227212
DO $$ BEGIN
228213
ALTER TABLE "Post" ADD CONSTRAINT "Post_userId_User_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
229214
EXCEPTION

drizzle/0011_add_series.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--> statement-breakpoint
2+
CREATE TABLE IF NOT EXISTS "Series" (
3+
"id" SERIAL PRIMARY KEY,
4+
"name" TEXT NOT NULL,
5+
"userId" text NOT NULL,
6+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
7+
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL
8+
);
9+
-->statement-breakpoint
10+
11+
ALTER TABLE "Post" ADD COLUMN "seriesId" INTEGER;
12+
--> statement-breakpoint
13+
DO $$ BEGIN
14+
ALTER TABLE "Post" ADD CONSTRAINT "Post_seriesId_fkey" FOREIGN KEY ("seriesId") REFERENCES "public"."Series" ("id") ON DELETE SET NULL;
15+
EXCEPTION
16+
WHEN duplicate_object THEN null;
17+
END $$

schema/post.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export const GetPostsSchema = z.object({
7272
tag: z.string().nullish(),
7373
});
7474

75+
export const FormDataSchema = z.object({
76+
seriesName: z.string().trim().optional()
77+
})
78+
7579
export type SavePostInput = z.TypeOf<typeof SavePostSchema>;
7680
export type ConfirmPostInput = z.TypeOf<typeof ConfirmPostSchema>;
7781

0 commit comments

Comments
 (0)