@@ -11,29 +11,42 @@ import {
1111import { ok } from '@/utils/api'
1212import { validateOrThrow } from '@/utils/validation'
1313
14- const MAX_HANDLES = 1000
14+ const MAX_HANDLES = 100
15+ const DEFAULT_PAGE_SIZE = 50
1516
1617const bodySchema = z . object ( {
1718 githubHandles : z
1819 . array ( z . string ( ) . min ( 1 ) )
1920 . min ( 1 )
2021 . max ( MAX_HANDLES , `Maximum ${ MAX_HANDLES } handles per request` ) ,
22+ page : z . number ( ) . int ( ) . min ( 1 ) . default ( 1 ) ,
23+ pageSize : z . number ( ) . int ( ) . min ( 1 ) . max ( MAX_HANDLES ) . default ( DEFAULT_PAGE_SIZE ) ,
2124} )
2225
2326export async function getAffiliations ( req : Request , res : Response ) : Promise < void > {
24- const { githubHandles } = validateOrThrow ( bodySchema , req . body )
27+ const { githubHandles, page , pageSize } = validateOrThrow ( bodySchema , req . body )
2528 const qx = optionsQx ( req )
2629
2730 const lowercasedHandles = githubHandles . map ( ( h ) => h . toLowerCase ( ) )
2831
32+ const offset = ( page - 1 ) * pageSize
33+ const pageHandles = lowercasedHandles . slice ( offset , offset + pageSize )
34+
2935 // Step 1: find verified members by github handles
30- const memberRows = await findMembersByGithubHandles ( qx , lowercasedHandles )
36+ const memberRows = await findMembersByGithubHandles ( qx , pageHandles )
3137
3238 const foundHandles = new Set ( memberRows . map ( ( r ) => r . githubHandle . toLowerCase ( ) ) )
33- const notFound = githubHandles . filter ( ( h ) => ! foundHandles . has ( h . toLowerCase ( ) ) )
39+ const notFound = pageHandles . filter ( ( h ) => ! foundHandles . has ( h ) )
3440
3541 if ( memberRows . length === 0 ) {
36- ok ( res , { total_found : 0 , contributors : [ ] , notFound } )
42+ ok ( res , {
43+ total : githubHandles . length ,
44+ page,
45+ pageSize,
46+ total_found : 0 ,
47+ contributors : [ ] ,
48+ notFound,
49+ } )
3750 return
3851 }
3952
@@ -60,5 +73,12 @@ export async function getAffiliations(req: Request, res: Response): Promise<void
6073 affiliations : affiliationsByMember . get ( member . memberId ) ?? [ ] ,
6174 } ) )
6275
63- ok ( res , { total_found : contributors . length , contributors, notFound } )
76+ ok ( res , {
77+ total : githubHandles . length ,
78+ page,
79+ pageSize,
80+ total_found : contributors . length ,
81+ contributors,
82+ notFound,
83+ } )
6484}
0 commit comments