From 2a54c62e981f226ec67cf36303a2db4c7d71354b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Mon, 15 Mar 2021 11:39:59 -0400 Subject: [PATCH] fix(context): pass object to service instead of json.stringify --- packages/auth/src/lib/shared/auth.service.ts | 14 ++++++------- .../common/src/lib/image/secure-image.pipe.ts | 4 ++-- .../context-manager/shared/context.service.ts | 20 +++++++++---------- .../poi-button/shared/poi.service.ts | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/auth/src/lib/shared/auth.service.ts b/packages/auth/src/lib/shared/auth.service.ts index 93c9db3cbe..e06b694694 100644 --- a/packages/auth/src/lib/shared/auth.service.ts +++ b/packages/auth/src/lib/shared/auth.service.ts @@ -37,23 +37,23 @@ export class AuthService { } login(username: string, password: string): Observable { - const myHeader = new HttpHeaders({'Content-Type': 'application/json'}); + const myHeader = new HttpHeaders({ 'Content-Type': 'application/json' }); - const body = JSON.stringify({ + const body = { username, password: this.encodePassword(password) - }); + }; return this.loginCall(body, myHeader); } loginWithToken(token: string, type: string): Observable { - const myHeader = new HttpHeaders({'Content-Type': 'application/json'}); + const myHeader = new HttpHeaders({ 'Content-Type': 'application/json' }); - const body = JSON.stringify({ + const body = { token, typeConnection: type - }); + }; return this.loginCall(body, myHeader); } @@ -126,7 +126,7 @@ export class AuthService { updateUser(user: User): Observable { const url = this.config.getConfig('auth.url'); - return this.http.patch(url, JSON.stringify(user)); + return this.http.patch(url, user); } private encodePassword(password: string) { diff --git a/packages/common/src/lib/image/secure-image.pipe.ts b/packages/common/src/lib/image/secure-image.pipe.ts index 4746b00dd1..632cb93313 100644 --- a/packages/common/src/lib/image/secure-image.pipe.ts +++ b/packages/common/src/lib/image/secure-image.pipe.ts @@ -13,12 +13,12 @@ export class SecureImagePipe implements PipeTransform { transform(url: string): Observable { const headers = new HttpHeaders({ 'Content-Type': 'text/plain', - 'activityInterceptor': 'false' + activityInterceptor: 'false' }); return this.http .get(url, { - headers: headers, + headers, responseType: 'blob' }) .pipe( diff --git a/packages/context/src/lib/context-manager/shared/context.service.ts b/packages/context/src/lib/context-manager/shared/context.service.ts index 881ee6f6bd..120b8bc339 100644 --- a/packages/context/src/lib/context-manager/shared/context.service.ts +++ b/packages/context/src/lib/context-manager/shared/context.service.ts @@ -181,7 +181,7 @@ export class ContextService { create(context: DetailedContext): Observable { const url = this.baseUrl + '/contexts'; - return this.http.post(url, JSON.stringify(context)).pipe( + return this.http.post(url, context).pipe( map((contextCreated) => { if (this.authService.authenticated) { contextCreated.permission = TypePermission[TypePermission.write]; @@ -197,7 +197,7 @@ export class ContextService { clone(id: string, properties = {}): Observable { const url = this.baseUrl + '/contexts/' + id + '/clone'; - return this.http.post(url, JSON.stringify(properties)).pipe( + return this.http.post(url, properties).pipe( map((contextCloned) => { contextCloned.permission = TypePermission[TypePermission.write]; this.contexts$.value.ours.unshift(contextCloned); @@ -209,7 +209,7 @@ export class ContextService { update(id: string, context: Context): Observable { const url = this.baseUrl + '/contexts/' + id; - return this.http.patch(url, JSON.stringify(context)); + return this.http.patch(url, context); } // ================================================================= @@ -219,7 +219,7 @@ export class ContextService { const association = { toolId }; - return this.http.post(url, JSON.stringify(association)); + return this.http.post(url, association); } deleteToolAssociation(contextId: string, toolId: string): Observable { @@ -243,13 +243,11 @@ export class ContextService { typePermission: type }; - return this.http - .post(url, JSON.stringify(association)) - .pipe( - catchError((res) => { - return [this.handleError(res, undefined, true)]; - }) - ); + return this.http.post(url, association).pipe( + catchError((res) => { + return [this.handleError(res, undefined, true)]; + }) + ); } deletePermissionAssociation( diff --git a/packages/context/src/lib/context-map-button/poi-button/shared/poi.service.ts b/packages/context/src/lib/context-map-button/poi-button/shared/poi.service.ts index a1ca3ff446..5b26e5f0af 100644 --- a/packages/context/src/lib/context-map-button/poi-button/shared/poi.service.ts +++ b/packages/context/src/lib/context-map-button/poi-button/shared/poi.service.ts @@ -29,6 +29,6 @@ export class PoiService { create(context: Poi): Observable { const url = this.baseUrl + '/pois'; - return this.http.post(url, JSON.stringify(context)); + return this.http.post(url, context); } }