From c7e493ce3d2855e61787d86714625bc7fc51f9bd Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Wed, 26 Apr 2023 21:37:38 -0600 Subject: AƱade vista de producto individual MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/api_client.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/clients/api_client.ts') diff --git a/src/clients/api_client.ts b/src/clients/api_client.ts index a7b5e0d..0e96c36 100644 --- a/src/clients/api_client.ts +++ b/src/clients/api_client.ts @@ -5,13 +5,28 @@ export class ApiClient { async get(path: string) { const request_url = `${ this.url }${ path }`; + const response = await this.makeRequest(request_url); + return response; + } + + async getProduct(id: string) { + const request_url = `${ this.url }/products/${ id }`; + const [product_response, product_reviews] = await Promise.all([ + this.makeRequest(request_url), + this.makeRequest(`${ request_url }/reviews`) + ]); + + return [product_response, product_reviews]; + } + + private async makeRequest(request_url: string) { try { const response = await axios.get(request_url); - return response; + return response } catch(error) { - return error.response; + return error; } } } \ No newline at end of file -- cgit v1.2.3