refactor: replace patch with delete for /api/document (#930)

This commit is contained in:
Jeremy 2025-04-14 00:11:44 -07:00 committed by GitHub
parent c937db3050
commit 5b4ad941d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 14 deletions

View file

@ -77,19 +77,22 @@ export async function POST(request: Request) {
return Response.json(document, { status: 200 }); 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 { searchParams } = new URL(request.url);
const id = searchParams.get('id'); const id = searchParams.get('id');
const timestamp = searchParams.get('timestamp');
const { timestamp }: { timestamp: string } = await request.json();
if (!id) { if (!id) {
return new Response('Missing id', { status: 400 }); return new Response('Missing id', { status: 400 });
} }
if (!timestamp) {
return new Response('Missing timestamp', { status: 400 });
}
const session = await auth(); const session = await auth();
if (!session || !session.user) { if (!session?.user?.id) {
return new Response('Unauthorized', { status: 401 }); return new Response('Unauthorized', { status: 401 });
} }

View file

@ -57,15 +57,15 @@ export const VersionFooter = ({
mutate( mutate(
`/api/document?id=${artifact.documentId}`, `/api/document?id=${artifact.documentId}`,
await fetch(`/api/document?id=${artifact.documentId}`, { await fetch(
method: 'PATCH', `/api/document?id=${artifact.documentId}&timestamp=${getDocumentTimestampByIndex(
body: JSON.stringify({ documents,
timestamp: getDocumentTimestampByIndex( currentVersionIndex,
documents, )}`,
currentVersionIndex, {
), method: 'DELETE',
}), },
}), ),
{ {
optimisticData: documents optimisticData: documents
? [ ? [

View file

@ -1,6 +1,6 @@
{ {
"name": "ai-chatbot", "name": "ai-chatbot",
"version": "3.0.1", "version": "3.0.2",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev --turbo", "dev": "next dev --turbo",