refactor: replace patch with delete for /api/document (#930)
This commit is contained in:
parent
c937db3050
commit
5b4ad941d3
3 changed files with 17 additions and 14 deletions
|
|
@ -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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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}×tamp=${getDocumentTimestampByIndex(
|
||||||
body: JSON.stringify({
|
documents,
|
||||||
timestamp: getDocumentTimestampByIndex(
|
currentVersionIndex,
|
||||||
documents,
|
)}`,
|
||||||
currentVersionIndex,
|
{
|
||||||
),
|
method: 'DELETE',
|
||||||
}),
|
},
|
||||||
}),
|
),
|
||||||
{
|
{
|
||||||
optimisticData: documents
|
optimisticData: documents
|
||||||
? [
|
? [
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue