From cbebedd51e1b4a2f709341b792dd073bac83f15d Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Fri, 12 May 2023 23:01:55 -0600 Subject: Añadido formulario de edición de cuenta MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/api_client.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/clients/api_client.ts') diff --git a/src/clients/api_client.ts b/src/clients/api_client.ts index fc2d361..93d713a 100644 --- a/src/clients/api_client.ts +++ b/src/clients/api_client.ts @@ -3,27 +3,19 @@ import Token from "../lib/token"; export class ApiClient { readonly url = "http://localhost:3000/api"; - token = new Token(); + public readonly token = new Token(); async authenticatedGet(path: string) { const request_url = `${ this.url }${ path }`; let request: any; - let options = { - headers: { - Authorization: this.token.get() - } - }; + let options = this.authorizationHeaders(); request = await this.makeGetRequest(request_url, options); if(request.response) { // Let's try with a refreshed token. this.token.refresh() - options = { - headers: { - Authorization: this.token.getRefresh() - } - }; + options = this.authorizationHeaders(); request = await this.makeGetRequest(request_url, options); } @@ -44,6 +36,14 @@ export class ApiClient { return response; } + async put(path: string, data: FormData) { + const request_url = `${ this.url }${ path }`; + const options = this.authorizationHeaders(); + const response = await axios.put(request_url, data, options); + + return response; + } + async getProduct(id: string) { const request_url = `${ this.url }/products/${ id }`; const [product_response, product_reviews] = await Promise.all([ @@ -63,4 +63,12 @@ export class ApiClient { return error; } } + + private authorizationHeaders() { + return { + headers: { + Authorization: this.token.get() + } + }; + } } \ No newline at end of file -- cgit v1.2.3