From 5b4ad941d3a16abe908f561e758001bab916fcce Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 14 Apr 2025 00:11:44 -0700 Subject: [PATCH] refactor: replace patch with delete for /api/document (#930) --- app/(chat)/api/document/route.ts | 11 +++++++---- components/version-footer.tsx | 18 +++++++++--------- package.json | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/(chat)/api/document/route.ts b/app/(chat)/api/document/route.ts index 656c2e0..862d49f 100644 --- a/app/(chat)/api/document/route.ts +++ b/app/(chat)/api/document/route.ts @@ -77,19 +77,22 @@ export async function POST(request: Request) { return Response.json(document, { status: 200 }); } -export async function PATCH(request: Request) { +export async function DELETE(request: Request) { const { searchParams } = new URL(request.url); const id = searchParams.get('id'); - - const { timestamp }: { timestamp: string } = await request.json(); + const timestamp = searchParams.get('timestamp'); if (!id) { return new Response('Missing id', { status: 400 }); } + if (!timestamp) { + return new Response('Missing timestamp', { status: 400 }); + } + const session = await auth(); - if (!session || !session.user) { + if (!session?.user?.id) { return new Response('Unauthorized', { status: 401 }); } diff --git a/components/version-footer.tsx b/components/version-footer.tsx index 4985daa..49b8760 100644 --- a/components/version-footer.tsx +++ b/components/version-footer.tsx @@ -57,15 +57,15 @@ export const VersionFooter = ({ mutate( `/api/document?id=${artifact.documentId}`, - await fetch(`/api/document?id=${artifact.documentId}`, { - method: 'PATCH', - body: JSON.stringify({ - timestamp: getDocumentTimestampByIndex( - documents, - currentVersionIndex, - ), - }), - }), + await fetch( + `/api/document?id=${artifact.documentId}×tamp=${getDocumentTimestampByIndex( + documents, + currentVersionIndex, + )}`, + { + method: 'DELETE', + }, + ), { optimisticData: documents ? [ diff --git a/package.json b/package.json index 0b85532..7eb8d94 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ai-chatbot", - "version": "3.0.1", + "version": "3.0.2", "private": true, "scripts": { "dev": "next dev --turbo",