Skip to content

Commit 2d60d25

Browse files
committed
fix cold email get
1 parent 547f8a4 commit 2d60d25

File tree

1 file changed

+9
-8
lines changed
  • apps/web/app/api/user/cold-email

1 file changed

+9
-8
lines changed

apps/web/app/api/user/cold-email/route.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { NextResponse } from "next/server";
2-
import { auth } from "@/app/api/auth/[...nextauth]/auth";
32
import prisma from "@/utils/prisma";
4-
import { withError } from "@/utils/middleware";
3+
import { withEmailAccount } from "@/utils/middleware";
54
import { ColdEmailStatus } from "@prisma/client";
65

76
const LIMIT = 50;
87

98
export type ColdEmailsResponse = Awaited<ReturnType<typeof getColdEmails>>;
109

1110
async function getColdEmails(
12-
{ userId, status }: { userId: string; status: ColdEmailStatus },
11+
{
12+
emailAccountId,
13+
status,
14+
}: { emailAccountId: string; status: ColdEmailStatus },
1315
page: number,
1416
) {
1517
const where = {
16-
userId,
18+
emailAccountId,
1719
status,
1820
};
1921

@@ -39,17 +41,16 @@ async function getColdEmails(
3941
return { coldEmails, totalPages: Math.ceil(count / LIMIT) };
4042
}
4143

42-
export const GET = withError(async (request) => {
43-
const session = await auth();
44-
if (!session?.user) return NextResponse.json({ error: "Not authenticated" });
44+
export const GET = withEmailAccount(async (request) => {
45+
const emailAccountId = request.auth.emailAccountId;
4546

4647
const url = new URL(request.url);
4748
const page = Number.parseInt(url.searchParams.get("page") || "1");
4849
const status =
4950
(url.searchParams.get("status") as ColdEmailStatus | undefined) ||
5051
ColdEmailStatus.AI_LABELED_COLD;
5152

52-
const result = await getColdEmails({ userId: session.user.id, status }, page);
53+
const result = await getColdEmails({ emailAccountId, status }, page);
5354

5455
return NextResponse.json(result);
5556
});

0 commit comments

Comments
 (0)