@@ -134,7 +134,7 @@ export const getApiKey = async (): Promise<TypesGen.GenerateAPIKeyResponse> => {
134
134
export const getUsers = async (
135
135
options : TypesGen . UsersRequest ,
136
136
) : Promise < TypesGen . User [ ] > => {
137
- const url = buildURL ( "/api/v2/users" , options )
137
+ const url = getURLWithSearchParams ( "/api/v2/users" , options )
138
138
const response = await axios . get < TypesGen . User [ ] > ( url . toString ( ) )
139
139
return response . data
140
140
}
@@ -266,28 +266,19 @@ export const watchWorkspace = (workspaceId: string): EventSource => {
266
266
267
267
interface SearchParamOptions extends TypesGen . Pagination {
268
268
q ?: string
269
- filter ?: string
270
- }
271
-
272
- const buildURL = ( basePath : string , options : SearchParamOptions ) => {
273
- const url = new URL ( basePath )
274
- const keys = Object . keys ( options ) as ( keyof SearchParamOptions ) [ ]
275
- keys . forEach ( ( key ) => {
276
- const value = options [ key ] ?? ""
277
- url . searchParams . append ( key , value . toString ( ) )
278
- } )
279
- return url
280
269
}
281
270
282
271
export const getURLWithSearchParams = (
283
272
basePath : string ,
284
- filter ?: TypesGen . WorkspaceFilter | TypesGen . UsersRequest ,
273
+ options : SearchParamOptions
285
274
) : string => {
286
275
const searchParams = new URLSearchParams ( )
287
276
288
- if ( filter ?. q && filter . q !== "" ) {
289
- searchParams . append ( "q" , filter . q )
290
- }
277
+ const keys = Object . keys ( options ) as ( keyof SearchParamOptions ) [ ]
278
+ keys . forEach ( ( key ) => {
279
+ const value = options [ key ] ?? ""
280
+ searchParams . append ( key , value . toString ( ) )
281
+ } )
291
282
292
283
const searchString = searchParams . toString ( )
293
284
@@ -297,33 +288,16 @@ export const getURLWithSearchParams = (
297
288
export const getWorkspaces = async (
298
289
options : TypesGen . WorkspacesRequest ,
299
290
) : Promise < TypesGen . Workspace [ ] > => {
300
- const searchParams = new URLSearchParams ( )
301
- if ( options . limit ) {
302
- searchParams . set ( "limit" , options . limit . toString ( ) )
303
- }
304
- if ( options . offset ) {
305
- searchParams . set ( "offset" , options . offset . toString ( ) )
306
- }
307
- if ( options . q ) {
308
- searchParams . set ( "q" , options . q )
309
- }
310
-
311
- const response = await axios . get < TypesGen . Workspace [ ] > (
312
- `/api/v2/workspaces?${ searchParams . toString ( ) } ` ,
313
- )
291
+ const url = getURLWithSearchParams ( "/api/v2/workspaces" , options )
292
+ const response = await axios . get < TypesGen . Workspace [ ] > ( url )
314
293
return response . data
315
294
}
316
295
317
296
export const getWorkspacesCount = async (
318
297
options : TypesGen . WorkspaceCountRequest ,
319
298
) : Promise < TypesGen . WorkspaceCountResponse > => {
320
- const searchParams = new URLSearchParams ( )
321
- if ( options . q ) {
322
- searchParams . set ( "q" , options . q )
323
- }
324
- const response = await axios . get (
325
- `/api/v2/workspaces/count?${ searchParams . toString ( ) } ` ,
326
- )
299
+ const url = getURLWithSearchParams ( "/api/v2/workspaces/count" , options )
300
+ const response = await axios . get ( url )
327
301
return response . data
328
302
}
329
303
@@ -570,31 +544,16 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
570
544
export const getAuditLogs = async (
571
545
options : TypesGen . AuditLogsRequest ,
572
546
) : Promise < TypesGen . AuditLogResponse > => {
573
- const searchParams = new URLSearchParams ( )
574
- if ( options . limit ) {
575
- searchParams . set ( "limit" , options . limit . toString ( ) )
576
- }
577
- if ( options . offset ) {
578
- searchParams . set ( "offset" , options . offset . toString ( ) )
579
- }
580
- if ( options . q ) {
581
- searchParams . set ( "q" , options . q )
582
- }
583
-
584
- const response = await axios . get ( `/api/v2/audit?${ searchParams . toString ( ) } ` )
547
+ const url = getURLWithSearchParams ( "/api/v2/audit" , options )
548
+ const response = await axios . get ( url )
585
549
return response . data
586
550
}
587
551
588
552
export const getAuditLogsCount = async (
589
553
options : TypesGen . AuditLogCountRequest = { } ,
590
554
) : Promise < TypesGen . AuditLogCountResponse > => {
591
- const searchParams = new URLSearchParams ( )
592
- if ( options . q ) {
593
- searchParams . set ( "q" , options . q )
594
- }
595
- const response = await axios . get (
596
- `/api/v2/audit/count?${ searchParams . toString ( ) } ` ,
597
- )
555
+ const url = getURLWithSearchParams ( "/api/v2/audit/count" , options )
556
+ const response = await axios . get ( url )
598
557
return response . data
599
558
}
600
559
0 commit comments