Add canvas interface (#461)
This commit is contained in:
parent
1a74a5ca9a
commit
b3cb0ea755
44 changed files with 7454 additions and 4691 deletions
33
app/(chat)/api/suggestions/route.ts
Normal file
33
app/(chat)/api/suggestions/route.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { auth } from '@/app/(auth)/auth';
|
||||
import { getSuggestionsByDocumentId } from '@/db/queries';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const documentId = searchParams.get('documentId');
|
||||
|
||||
if (!documentId) {
|
||||
return new Response('Not Found', { status: 404 });
|
||||
}
|
||||
|
||||
const session = await auth();
|
||||
|
||||
if (!session || !session.user) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const suggestions = await getSuggestionsByDocumentId({
|
||||
documentId,
|
||||
});
|
||||
|
||||
const [suggestion] = suggestions;
|
||||
|
||||
if (!suggestion) {
|
||||
return Response.json([], { status: 200 });
|
||||
}
|
||||
|
||||
if (suggestion.userId !== session.user.id) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
return Response.json(suggestions, { status: 200 });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue