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 });
}
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 });
}

View file

@ -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}&timestamp=${getDocumentTimestampByIndex(
documents,
currentVersionIndex,
)}`,
{
method: 'DELETE',
},
),
{
optimisticData: documents
? [

View file

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