@@ -132,10 +132,10 @@ export const getApiKey = async (): Promise<TypesGen.GenerateAPIKeyResponse> => {
132
132
}
133
133
134
134
export const getUsers = async (
135
- filter ? : TypesGen . UsersRequest ,
135
+ options : TypesGen . UsersRequest ,
136
136
) : Promise < TypesGen . User [ ] > => {
137
- const url = getURLWithSearchParams ( "/api/v2/users" , filter )
138
- const response = await axios . get < TypesGen . User [ ] > ( url )
137
+ const url = getURLWithSearchParams ( "/api/v2/users" , options )
138
+ const response = await axios . get < TypesGen . User [ ] > ( url . toString ( ) )
139
139
return response . data
140
140
}
141
141
@@ -264,51 +264,43 @@ export const watchWorkspace = (workspaceId: string): EventSource => {
264
264
)
265
265
}
266
266
267
+ interface SearchParamOptions extends TypesGen . Pagination {
268
+ q ?: string
269
+ }
270
+
267
271
export const getURLWithSearchParams = (
268
272
basePath : string ,
269
- filter ?: TypesGen . WorkspaceFilter | TypesGen . UsersRequest ,
273
+ options ?: SearchParamOptions ,
270
274
) : string => {
271
- const searchParams = new URLSearchParams ( )
272
-
273
- if ( filter ?. q && filter . q !== "" ) {
274
- searchParams . append ( "q" , filter . q )
275
+ if ( options ) {
276
+ const searchParams = new URLSearchParams ( )
277
+ const keys = Object . keys ( options ) as ( keyof SearchParamOptions ) [ ]
278
+ keys . forEach ( ( key ) => {
279
+ const value = options [ key ]
280
+ if ( value !== undefined && value !== "" ) {
281
+ searchParams . append ( key , value . toString ( ) )
282
+ }
283
+ } )
284
+ const searchString = searchParams . toString ( )
285
+ return searchString ? `${ basePath } ?${ searchString } ` : basePath
286
+ } else {
287
+ return basePath
275
288
}
276
-
277
- const searchString = searchParams . toString ( )
278
-
279
- return searchString ? `${ basePath } ?${ searchString } ` : basePath
280
289
}
281
290
282
291
export const getWorkspaces = async (
283
292
options : TypesGen . WorkspacesRequest ,
284
293
) : Promise < TypesGen . Workspace [ ] > => {
285
- const searchParams = new URLSearchParams ( )
286
- if ( options . limit ) {
287
- searchParams . set ( "limit" , options . limit . toString ( ) )
288
- }
289
- if ( options . offset ) {
290
- searchParams . set ( "offset" , options . offset . toString ( ) )
291
- }
292
- if ( options . q ) {
293
- searchParams . set ( "q" , options . q )
294
- }
295
-
296
- const response = await axios . get < TypesGen . Workspace [ ] > (
297
- `/api/v2/workspaces?${ searchParams . toString ( ) } ` ,
298
- )
294
+ const url = getURLWithSearchParams ( "/api/v2/workspaces" , options )
295
+ const response = await axios . get < TypesGen . Workspace [ ] > ( url )
299
296
return response . data
300
297
}
301
298
302
299
export const getWorkspacesCount = async (
303
300
options : TypesGen . WorkspaceCountRequest ,
304
301
) : Promise < TypesGen . WorkspaceCountResponse > => {
305
- const searchParams = new URLSearchParams ( )
306
- if ( options . q ) {
307
- searchParams . set ( "q" , options . q )
308
- }
309
- const response = await axios . get (
310
- `/api/v2/workspaces/count?${ searchParams . toString ( ) } ` ,
311
- )
302
+ const url = getURLWithSearchParams ( "/api/v2/workspaces/count" , options )
303
+ const response = await axios . get ( url )
312
304
return response . data
313
305
}
314
306
@@ -555,31 +547,16 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
555
547
export const getAuditLogs = async (
556
548
options : TypesGen . AuditLogsRequest ,
557
549
) : Promise < TypesGen . AuditLogResponse > => {
558
- const searchParams = new URLSearchParams ( )
559
- if ( options . limit ) {
560
- searchParams . set ( "limit" , options . limit . toString ( ) )
561
- }
562
- if ( options . offset ) {
563
- searchParams . set ( "offset" , options . offset . toString ( ) )
564
- }
565
- if ( options . q ) {
566
- searchParams . set ( "q" , options . q )
567
- }
568
-
569
- const response = await axios . get ( `/api/v2/audit?${ searchParams . toString ( ) } ` )
550
+ const url = getURLWithSearchParams ( "/api/v2/audit" , options )
551
+ const response = await axios . get ( url )
570
552
return response . data
571
553
}
572
554
573
555
export const getAuditLogsCount = async (
574
556
options : TypesGen . AuditLogCountRequest = { } ,
575
557
) : Promise < TypesGen . AuditLogCountResponse > => {
576
- const searchParams = new URLSearchParams ( )
577
- if ( options . q ) {
578
- searchParams . set ( "q" , options . q )
579
- }
580
- const response = await axios . get (
581
- `/api/v2/audit/count?${ searchParams . toString ( ) } ` ,
582
- )
558
+ const url = getURLWithSearchParams ( "/api/v2/audit/count" , options )
559
+ const response = await axios . get ( url )
583
560
return response . data
584
561
}
585
562
0 commit comments