Skip to content

Commit 5b4ad94

Browse files
refactor: replace patch with delete for /api/document (vercel#930)
1 parent c937db3 commit 5b4ad94

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

app/(chat)/api/document/route.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,22 @@ export async function POST(request: Request) {
7777
return Response.json(document, { status: 200 });
7878
}
7979

80-
export async function PATCH(request: Request) {
80+
export async function DELETE(request: Request) {
8181
const { searchParams } = new URL(request.url);
8282
const id = searchParams.get('id');
83-
84-
const { timestamp }: { timestamp: string } = await request.json();
83+
const timestamp = searchParams.get('timestamp');
8584

8685
if (!id) {
8786
return new Response('Missing id', { status: 400 });
8887
}
8988

89+
if (!timestamp) {
90+
return new Response('Missing timestamp', { status: 400 });
91+
}
92+
9093
const session = await auth();
9194

92-
if (!session || !session.user) {
95+
if (!session?.user?.id) {
9396
return new Response('Unauthorized', { status: 401 });
9497
}
9598

components/version-footer.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ export const VersionFooter = ({
5757

5858
mutate(
5959
`/api/document?id=${artifact.documentId}`,
60-
await fetch(`/api/document?id=${artifact.documentId}`, {
61-
method: 'PATCH',
62-
body: JSON.stringify({
63-
timestamp: getDocumentTimestampByIndex(
64-
documents,
65-
currentVersionIndex,
66-
),
67-
}),
68-
}),
60+
await fetch(
61+
`/api/document?id=${artifact.documentId}&timestamp=${getDocumentTimestampByIndex(
62+
documents,
63+
currentVersionIndex,
64+
)}`,
65+
{
66+
method: 'DELETE',
67+
},
68+
),
6969
{
7070
optimisticData: documents
7171
? [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ai-chatbot",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"private": true,
55
"scripts": {
66
"dev": "next dev --turbo",

0 commit comments

Comments
 (0)