(request: Request)
| 8 | import { ChatSDKError } from '@/lib/errors'; |
| 9 | |
| 10 | export async function GET(request: Request) { |
| 11 | const { searchParams } = new URL(request.url); |
| 12 | const id = searchParams.get('id'); |
| 13 | |
| 14 | if (!id) { |
| 15 | return new ChatSDKError( |
| 16 | 'bad_request:api', |
| 17 | 'Parameter id is missing', |
| 18 | ).toResponse(); |
| 19 | } |
| 20 | |
| 21 | const session = await auth(); |
| 22 | |
| 23 | if (!session?.user) { |
| 24 | return new ChatSDKError('unauthorized:document').toResponse(); |
| 25 | } |
| 26 | |
| 27 | const documents = await getDocumentsById({ id }); |
| 28 | |
| 29 | const [document] = documents; |
| 30 | |
| 31 | if (!document) { |
| 32 | return new ChatSDKError('not_found:document').toResponse(); |
| 33 | } |
| 34 | |
| 35 | if (document.userId !== session.user.id) { |
| 36 | return new ChatSDKError('forbidden:document').toResponse(); |
| 37 | } |
| 38 | |
| 39 | return Response.json(documents, { status: 200 }); |
| 40 | } |
| 41 | |
| 42 | export async function POST(request: Request) { |
| 43 | const { searchParams } = new URL(request.url); |
nothing calls this directly
no test coverage detected