1
1
import { NextResponse } from "next/server" ;
2
- import { auth } from "@/app/api/auth/[...nextauth]/auth" ;
3
2
import prisma from "@/utils/prisma" ;
4
- import { withError } from "@/utils/middleware" ;
3
+ import { withEmailAccount } from "@/utils/middleware" ;
5
4
import { ColdEmailStatus } from "@prisma/client" ;
6
5
7
6
const LIMIT = 50 ;
8
7
9
8
export type ColdEmailsResponse = Awaited < ReturnType < typeof getColdEmails > > ;
10
9
11
10
async function getColdEmails (
12
- { userId, status } : { userId : string ; status : ColdEmailStatus } ,
11
+ {
12
+ emailAccountId,
13
+ status,
14
+ } : { emailAccountId : string ; status : ColdEmailStatus } ,
13
15
page : number ,
14
16
) {
15
17
const where = {
16
- userId ,
18
+ emailAccountId ,
17
19
status,
18
20
} ;
19
21
@@ -39,17 +41,16 @@ async function getColdEmails(
39
41
return { coldEmails, totalPages : Math . ceil ( count / LIMIT ) } ;
40
42
}
41
43
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 ;
45
46
46
47
const url = new URL ( request . url ) ;
47
48
const page = Number . parseInt ( url . searchParams . get ( "page" ) || "1" ) ;
48
49
const status =
49
50
( url . searchParams . get ( "status" ) as ColdEmailStatus | undefined ) ||
50
51
ColdEmailStatus . AI_LABELED_COLD ;
51
52
52
- const result = await getColdEmails ( { userId : session . user . id , status } , page ) ;
53
+ const result = await getColdEmails ( { emailAccountId , status } , page ) ;
53
54
54
55
return NextResponse . json ( result ) ;
55
56
} ) ;
0 commit comments