Added newBookmarkSchema

master
TZGyn 2 years ago
parent 7ff7f673e7
commit df63c96521
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -1,4 +1,4 @@
import { bookmarkSchema } from '@/types' import { newBookmarkSchema } from '@/types'
import { NextRequest, NextResponse } from 'next/server' import { NextRequest, NextResponse } from 'next/server'
import { db, bookmark } from '@/lib/schema' import { db, bookmark } from '@/lib/schema'
import { eq } from 'drizzle-orm' import { eq } from 'drizzle-orm'
@ -12,7 +12,7 @@ export const GET = async () => {
export const POST = async (request: NextRequest) => { export const POST = async (request: NextRequest) => {
const body = await request.json() const body = await request.json()
const newBookmark = bookmarkSchema.safeParse(body) const newBookmark = newBookmarkSchema.safeParse(body)
if (newBookmark.success) { if (newBookmark.success) {
await db.insert(bookmark).values(newBookmark.data) await db.insert(bookmark).values(newBookmark.data)

@ -5,12 +5,20 @@ export type IconSvgProps = SVGProps<SVGSVGElement> & {
size?: number size?: number
} }
export const bookmarkSchema = z.object({ const bookmark = {
id: z.number(),
name: z.string(), name: z.string(),
link: z.string(), link: z.string(),
description: z.string(), description: z.string(),
url: z.string().url(), url: z.string().url(),
}
export const bookmarkSchema = z.object({
id: z.number(),
...bookmark,
})
export const newBookmarkSchema = z.object({
...bookmark,
}) })
export type Bookmark = z.infer<typeof bookmarkSchema> export type Bookmark = z.infer<typeof bookmarkSchema>

Loading…
Cancel
Save