From df63c96521b94aaef805b77fa616ee6ac9179310 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Fri, 11 Aug 2023 16:10:04 +0800 Subject: [PATCH] Added newBookmarkSchema --- app/api/bookmark/route.ts | 4 ++-- types/index.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/api/bookmark/route.ts b/app/api/bookmark/route.ts index 48f5b47..abf0913 100644 --- a/app/api/bookmark/route.ts +++ b/app/api/bookmark/route.ts @@ -1,4 +1,4 @@ -import { bookmarkSchema } from '@/types' +import { newBookmarkSchema } from '@/types' import { NextRequest, NextResponse } from 'next/server' import { db, bookmark } from '@/lib/schema' import { eq } from 'drizzle-orm' @@ -12,7 +12,7 @@ export const GET = async () => { export const POST = async (request: NextRequest) => { const body = await request.json() - const newBookmark = bookmarkSchema.safeParse(body) + const newBookmark = newBookmarkSchema.safeParse(body) if (newBookmark.success) { await db.insert(bookmark).values(newBookmark.data) diff --git a/types/index.ts b/types/index.ts index 5d98270..d2070cb 100644 --- a/types/index.ts +++ b/types/index.ts @@ -5,12 +5,20 @@ export type IconSvgProps = SVGProps & { size?: number } -export const bookmarkSchema = z.object({ - id: z.number(), +const bookmark = { name: z.string(), link: z.string(), description: z.string(), url: z.string().url(), +} + +export const bookmarkSchema = z.object({ + id: z.number(), + ...bookmark, +}) + +export const newBookmarkSchema = z.object({ + ...bookmark, }) export type Bookmark = z.infer