Elliott-Chong / chatpdf-yt

https://chatpdf-elliott.vercel.app
694 stars 284 forks source link

No overload matches this call. #11

Open AymanBoumait opened 1 year ago

AymanBoumait commented 1 year ago

Error:

No overload matches this call.
  Overload 1 of 2, '(value: { userId: string | SQL<unknown> | Placeholder<string, any>; pdfName: string | SQL<unknown> | Placeholder<string, any>; pdfUrl: string | SQL<unknown> | Placeholder<...>; fileKey: string | ... 1 more ... | Placeholder<...>; id?: number | ... 2 more ... | undefined; createdAt?: Date | ... 2 more ... | undefined; }): PgInsert<...>', gave the following error.
    Type 'void' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any>'.
  Overload 2 of 2, '(values: { userId: string | SQL<unknown> | Placeholder<string, any>; pdfName: string | SQL<unknown> | Placeholder<string, any>; pdfUrl: string | SQL<unknown> | Placeholder<...>; fileKey: string | ... 1 more ... | Placeholder<...>; id?: number | ... 2 more ... | undefined; createdAt?: Date | ... 2 more ... | undefined; }[]): PgInsert<...>', gave the following error.
    Argument of type '{ fileKey: any; pdfName: any; pdfUrl: void; userId: string; }' is not assignable to parameter of type '{ userId: string | SQL<unknown> | Placeholder<string, any>; pdfName: string | SQL<unknown> | Placeholder<string, any>; pdfUrl: string | SQL<unknown> | Placeholder<...>; fileKey: string | ... 1 more ... | Placeholder<...>; id?: number | ... 2 more ... | undefined; createdAt?: Date | ... 2 more ... | undefined; }[]'.
      Object literal may only specify known properties, and 'fileKey' does not exist in type '{ userId: string | SQL<unknown> | Placeholder<string, any>; pdfName: string | SQL<unknown> | Placeholder<string, any>; pdfUrl: string | SQL<unknown> | Placeholder<...>; fileKey: string | ... 1 more ... | Placeholder<...>; id?: number | ... 2 more ... | undefined; createdAt?: Date | ... 2 more ... | undefined; }[]'.
import { db } from "@/lib/db";
import { chats } from "@/lib/db/schema";
import { loadS3IntoPinecone } from "@/lib/pinecone";
import { getS3Url } from "@/lib/s3";
import { auth } from "@clerk/nextjs";
import { NextResponse } from "next/server";

// /api/create-chat
export async function POST(req: Request, res: Response) {
  const { userId } = await auth();
  if (!userId) {
    return NextResponse.json({ error: "unauthorized" }, { status: 401 });
  }
  try {
    const body = await req.json();
    const { file_key, file_name } = body;
    console.log(file_key, file_name);
    await loadS3IntoPinecone(file_key);
    const chat_id = await db
      .insert(chats)
      .values({
        fileKey: file_key,
        pdfName: file_name,
        pdfUrl: getS3Url(file_key),
        userId,
      })
      .returning({
        insertedId: chats.id,
      });

    return NextResponse.json(
      {
        chat_id: chat_id[0].insertedId,
      },
      { status: 200 }
    );
  } catch (error) {
    console.error(error);
    return NextResponse.json(
      { error: "internal server error" },
      { status: 500 }
    );
  }
}
AymanBoumait commented 1 year ago

@Elliott-Chong