4
0
forked from crowetic/commerce
This commit is contained in:
Luis Alvarez 2020-09-30 12:32:46 -05:00
parent 2a29cfe3c7
commit 9ca977c44f

View File

@ -17,8 +17,8 @@ export interface GetAllProductsResult<T> {
} }
export default class BigcommerceAPI implements CommerceAPI { export default class BigcommerceAPI implements CommerceAPI {
protected commerceUrl: string; commerceUrl: string;
protected apiToken: string; apiToken: string;
constructor({ commerceUrl, apiToken }: CommerceAPIOptions) { constructor({ commerceUrl, apiToken }: CommerceAPIOptions) {
this.commerceUrl = commerceUrl; this.commerceUrl = commerceUrl;
@ -52,24 +52,20 @@ export default class BigcommerceAPI implements CommerceAPI {
async getAllProducts<T>(opts: { async getAllProducts<T>(opts: {
query: string; query: string;
}): Promise<GetAllProductsResult<T>>; }): Promise<GetAllProductsResult<T>>;
async getAllProducts<T = GetAllProductsQuery>({
query,
}: { query?: string } = {}): Promise<
GetAllProductsResult<T | GetAllProductsQuery>
// T extends GetAllProductsQuery
// ? GetAllProductsResult<T['site']['products']['edges']>
// : Partial<GetAllProductsResult<any>>
> {
if (!query) {
const data = await this.fetch<GetAllProductsQuery>(getAllProductsQuery);
return { async getAllProducts(opts?: {
products: data.site.products.edges, query?: string;
}; }): Promise<GetAllProductsResult<GetAllProductsQuery>>;
}
async getAllProducts({
query = getAllProductsQuery,
}: { query?: string } = {}): Promise<
GetAllProductsResult<RecursivePartial<GetAllProductsQuery>>
> {
const data = await this.fetch<RecursivePartial<GetAllProductsQuery>>(query);
return { return {
products: undefined, products: data?.site?.products?.edges,
}; };
} }
} }