Stop using multiple apiService instances

This commit is contained in:
Tom Bloor 2017-09-08 15:22:15 +01:00
parent 7d637e84e4
commit cf1980d768
8 changed files with 14 additions and 17 deletions

View file

@ -7,7 +7,6 @@ import 'rxjs/add/operator/map';
@Component({ @Component({
templateUrl: 'login.component.html', templateUrl: 'login.component.html',
providers: [ApiService]
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
signin: FormGroup; signin: FormGroup;

View file

@ -8,7 +8,6 @@ import 'rxjs/add/operator/map';
@Component({ @Component({
templateUrl: 'register.component.html', templateUrl: 'register.component.html',
providers: [ApiService]
}) })
export class RegisterComponent { export class RegisterComponent {

View file

@ -6,7 +6,6 @@ import 'rxjs/add/operator/map';
@Component({ @Component({
templateUrl: 'account-edit.component.html', templateUrl: 'account-edit.component.html',
providers: [ApiService]
}) })
export class AccountEditComponent implements OnInit { export class AccountEditComponent implements OnInit {
settingForm: FormGroup; settingForm: FormGroup;

View file

@ -8,7 +8,6 @@ import 'rxjs/add/operator/map';
@Component({ @Component({
templateUrl: 'add-data.component.html', templateUrl: 'add-data.component.html',
providers: [ApiService]
}) })
export class AddDataComponent { export class AddDataComponent {
payrollForm: FormGroup; payrollForm: FormGroup;

View file

@ -6,7 +6,6 @@ import 'rxjs/add/operator/map';
@Component({ @Component({
templateUrl: 'feedback.component.html', templateUrl: 'feedback.component.html',
providers: [ApiService]
}) })
export class FeedbackComponent { export class FeedbackComponent {
feedbackForm: FormGroup; feedbackForm: FormGroup;

View file

@ -11,7 +11,6 @@ import 'rxjs/add/operator/map';
@Component({ @Component({
templateUrl: 'transaction-log.component.html', templateUrl: 'transaction-log.component.html',
providers: [ApiService]
}) })
export class TransactionLogComponent { export class TransactionLogComponent {

View file

@ -5,7 +5,6 @@ import { Router } from '@angular/router';
@Component({ @Component({
selector: 'app-dashboard', selector: 'app-dashboard',
templateUrl: './full-layout.component.html', templateUrl: './full-layout.component.html',
providers: [ApiService]
}) })
export class FullLayoutComponent implements OnInit { export class FullLayoutComponent implements OnInit {
displayName: any; displayName: any;

View file

@ -19,9 +19,7 @@ export class ApiService {
} }
public post(url: string, data: any = {}) { public post(url: string, data: any = {}) {
if ( this.sessionKey != null ) { data.session_key = this.sessionKey;
data.session_key = this.sessionKey;
}
return this.http.post( return this.http.post(
this.apiUrl + url, this.apiUrl + url,
data data
@ -77,12 +75,18 @@ export class ApiService {
public logout() { public logout() {
console.log(this.sessionKey); console.log(this.sessionKey);
const key = this.sessionKey; const key = this.sessionKey;
return this.http.post( return this.http
this.apiUrl + '/logout', .post(
{ this.apiUrl + '/logout',
session_key : key, { session_key : key },
} )
).map( response => { this.removeSessionKey(); return response.json(); } ); .map(
response => {
localStorage.clear();
this.sessionKey = null;
return response.json();
}
);
} }
// Submits feedback // Submits feedback