Skip to content

Commit 10cb3d5

Browse files
committed
add to client methods
1 parent 342baf1 commit 10cb3d5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
import type { AutumnPromise } from "@sdk/response";
22
import type { Product } from "src/sdk/products/prodTypes";
33
import 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
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export interface ListProductsParams {
22
customerId?: string;
3+
entityId?: string;
34
}

0 commit comments

Comments
 (0)