File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
package/src/libraries/react/client Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 11import type { AutumnPromise } from "@sdk/response" ;
22import type { Product } from "src/sdk/products/prodTypes" ;
33import type { AutumnClient } from "./ReactAutumnClient" ;
4+ import type { ListProductsParams } from "./types/clientProdTypes" ;
45
5- export async function listProductsMethod ( this : AutumnClient ) : AutumnPromise < {
6+ export async function listProductsMethod ( this : AutumnClient , params ?: ListProductsParams ) : AutumnPromise < {
67 list : Product [ ] ;
78} > {
8- const res = await this . get ( `${ this . prefix } /products` ) ;
9+ let path = `${ this . prefix } /products` ;
10+
11+ // Append query params to the path
12+ // available: customer_id (optional), entity_id (optional)
13+ const queryParams = new URLSearchParams ( ) ;
14+ for ( const [ key , value ] of Object . entries ( params ?? { } ) ) {
15+ if ( value !== undefined ) {
16+ queryParams . append ( key , String ( value ) ) ;
17+ }
18+ }
19+
20+ // minor optimization to avoid adding ? if no query params
21+ const queryString = queryParams . toString ( ) ;
22+ if ( queryString ) {
23+ path += `?${ queryString } ` ;
24+ }
25+
26+ const res = await this . get ( path ) ;
927 return res ;
1028}
Original file line number Diff line number Diff line change 11export interface ListProductsParams {
22 customerId ?: string ;
3+ entityId ?: string ;
34}
You can’t perform that action at this time.
0 commit comments