From cf1980d768a1b48459f3076381f717459bc99d31 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Fri, 8 Sep 2017 15:22:15 +0100 Subject: [PATCH] Stop using multiple apiService instances --- src/app/auth/login.component.ts | 1 - src/app/auth/register.component.ts | 3 +-- src/app/dashboard/account-edit.component.ts | 1 - src/app/dashboard/add-data.component.ts | 1 - src/app/dashboard/feedback.component.ts | 1 - .../dashboard/transaction-log.component.ts | 1 - src/app/layouts/full-layout.component.ts | 1 - src/app/providers/api-service.ts | 22 +++++++++++-------- 8 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/app/auth/login.component.ts b/src/app/auth/login.component.ts index 46848a4..77b2751 100644 --- a/src/app/auth/login.component.ts +++ b/src/app/auth/login.component.ts @@ -7,7 +7,6 @@ import 'rxjs/add/operator/map'; @Component({ templateUrl: 'login.component.html', - providers: [ApiService] }) export class LoginComponent implements OnInit { signin: FormGroup; diff --git a/src/app/auth/register.component.ts b/src/app/auth/register.component.ts index 4cc5eb4..ebc69d2 100644 --- a/src/app/auth/register.component.ts +++ b/src/app/auth/register.component.ts @@ -8,7 +8,6 @@ import 'rxjs/add/operator/map'; @Component({ templateUrl: 'register.component.html', - providers: [ApiService] }) export class RegisterComponent { @@ -134,4 +133,4 @@ export class RegisterComponent { } -} \ No newline at end of file +} diff --git a/src/app/dashboard/account-edit.component.ts b/src/app/dashboard/account-edit.component.ts index 707b93c..eedd3ad 100644 --- a/src/app/dashboard/account-edit.component.ts +++ b/src/app/dashboard/account-edit.component.ts @@ -6,7 +6,6 @@ import 'rxjs/add/operator/map'; @Component({ templateUrl: 'account-edit.component.html', - providers: [ApiService] }) export class AccountEditComponent implements OnInit { settingForm: FormGroup; diff --git a/src/app/dashboard/add-data.component.ts b/src/app/dashboard/add-data.component.ts index 3691210..de07cfa 100644 --- a/src/app/dashboard/add-data.component.ts +++ b/src/app/dashboard/add-data.component.ts @@ -8,7 +8,6 @@ import 'rxjs/add/operator/map'; @Component({ templateUrl: 'add-data.component.html', - providers: [ApiService] }) export class AddDataComponent { payrollForm: FormGroup; diff --git a/src/app/dashboard/feedback.component.ts b/src/app/dashboard/feedback.component.ts index f1f1f93..11d56d4 100644 --- a/src/app/dashboard/feedback.component.ts +++ b/src/app/dashboard/feedback.component.ts @@ -6,7 +6,6 @@ import 'rxjs/add/operator/map'; @Component({ templateUrl: 'feedback.component.html', - providers: [ApiService] }) export class FeedbackComponent { feedbackForm: FormGroup; diff --git a/src/app/dashboard/transaction-log.component.ts b/src/app/dashboard/transaction-log.component.ts index cf6f982..f707e83 100644 --- a/src/app/dashboard/transaction-log.component.ts +++ b/src/app/dashboard/transaction-log.component.ts @@ -11,7 +11,6 @@ import 'rxjs/add/operator/map'; @Component({ templateUrl: 'transaction-log.component.html', - providers: [ApiService] }) export class TransactionLogComponent { diff --git a/src/app/layouts/full-layout.component.ts b/src/app/layouts/full-layout.component.ts index 375151a..7007e35 100644 --- a/src/app/layouts/full-layout.component.ts +++ b/src/app/layouts/full-layout.component.ts @@ -5,7 +5,6 @@ import { Router } from '@angular/router'; @Component({ selector: 'app-dashboard', templateUrl: './full-layout.component.html', - providers: [ApiService] }) export class FullLayoutComponent implements OnInit { displayName: any; diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index da05708..e0f27a2 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -19,9 +19,7 @@ export class ApiService { } public post(url: string, data: any = {}) { - if ( this.sessionKey != null ) { - data.session_key = this.sessionKey; - } + data.session_key = this.sessionKey; return this.http.post( this.apiUrl + url, data @@ -77,12 +75,18 @@ export class ApiService { public logout() { console.log(this.sessionKey); const key = this.sessionKey; - return this.http.post( - this.apiUrl + '/logout', - { - session_key : key, - } - ).map( response => { this.removeSessionKey(); return response.json(); } ); + return this.http + .post( + this.apiUrl + '/logout', + { session_key : key }, + ) + .map( + response => { + localStorage.clear(); + this.sessionKey = null; + return response.json(); + } + ); } // Submits feedback