Fix: Login deleting old clients was conflicting with login history

Chore: Moved to angular linting using the recommended plugins / settings
This commit is contained in:
2020-12-08 12:09:19 +05:30
parent d5048bc455
commit 57ef355170
176 changed files with 940 additions and 831 deletions

View File

@ -1,5 +1,5 @@
import { inject, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { AccountService } from './account.service';

View File

@ -7,10 +7,6 @@ import { Account } from './account';
import { AccountBalance } from './account-balance';
import { ErrorLoggerService } from './error-logger.service';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/accounts';
const serviceName = 'AccountService';
@ -20,53 +16,41 @@ export class AccountService {
get(id: string | null): Observable<Account> {
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return <Observable<Account>>(
this.http
.get<Account>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
);
return this.http
.get<Account>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id as Observable<Account>=${id}`))) as Observable<Account>;
}
list(): Observable<Account[]> {
return <Observable<Account[]>>(
this.http
.get<Account[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
return this.http
.get<Account[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Account[]>;
}
paymentAutocomplete(query: string): Observable<Account[]> {
const options = { params: new HttpParams().set('q', query).set('t', '1') };
return <Observable<Account[]>>(
this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
return this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Account[]>;
}
receiptAutocomplete(query: string): Observable<Account[]> {
const options = { params: new HttpParams().set('q', query).set('t', '1') };
return <Observable<Account[]>>(
this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
return this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Account[]>;
}
save(account: Account): Observable<Account> {
return <Observable<Account>>(
this.http
.post<Account>(`${url}`, account, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save')))
);
return this.http
.post<Account>(`${url}`, account)
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<Account>;
}
update(account: Account): Observable<Account> {
return <Observable<Account>>(
this.http
.put<Account>(`${url}/${account.id}`, account, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update')))
);
return this.http
.put<Account>(`${url}/${account.id}`, account)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<Account>;
}
saveOrUpdate(account: Account): Observable<Account> {
@ -77,28 +61,22 @@ export class AccountService {
}
delete(id: string): Observable<Account> {
return <Observable<Account>>(
this.http
.delete<Account>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
);
return this.http
.delete<Account>(`${url}/${id}`)
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Account>;
}
autocomplete(query: string): Observable<Account[]> {
const options = { params: new HttpParams().set('q', query) };
return <Observable<Account[]>>(
this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete')))
);
return this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable<Account[]>;
}
balance(id: string, date: string): Observable<AccountBalance> {
const options = { params: new HttpParams().set('d', date) };
return <Observable<AccountBalance>>(
this.http
.get<AccountBalance>(`${url}/${id}/balance`, options)
.pipe(catchError(this.log.handleError(serviceName, 'balance')))
);
return this.http
.get<AccountBalance>(`${url}/${id}/balance`, options)
.pipe(catchError(this.log.handleError(serviceName, 'balance'))) as Observable<AccountBalance>;
}
}

View File

@ -15,10 +15,8 @@ export class BatchService {
autocomplete(date: string, term: string): Observable<Batch[]> {
const options = { params: new HttpParams().set('q', term).set('d', date) };
return <Observable<Batch[]>>(
this.http
.get<Batch[]>(url, options)
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete')))
);
return this.http
.get<Batch[]>(url, options)
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable<Batch[]>;
}
}

View File

@ -14,6 +14,7 @@ export class ErrorLoggerService {
/**
* Handle Http operation that failed.
* Let the app continue.
*
* @param operation - name of the operation that failed
* @param result - optional value to return as the observable result
*/

View File

@ -46,7 +46,9 @@ export class ErrorInterceptor implements HttpInterceptor {
data: {
title: 'Logged out!',
content:
'You have been logged out.\nYou can press Cancel to stay on page and login in another tab to resume here, or you can press Ok to navigate to the login page.',
'You have been logged out.\n' +
'You can press Cancel to stay on page and login in another tab to resume here, ' +
'or you can press Ok to navigate to the login page.',
},
});
dialogRef.afterClosed().subscribe((result: boolean) => {

View File

@ -69,7 +69,7 @@
<mat-icon>account_box</mat-icon>
{{ name }}
</button>
<a mat-button routerLink="/login" *ngIf="!(auth.currentUser | async)">
<a mat-button routerLink="/login" *ngIf="(auth.currentUser | async) === null">
<mat-icon>account_box</mat-icon>
Login</a
>

View File

@ -1,5 +1,5 @@
import { inject, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { VoucherService } from './voucher.service';

View File

@ -6,10 +6,6 @@ import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from './error-logger.service';
import { Voucher } from './voucher';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api';
const serviceName = 'VoucherService';
@ -36,11 +32,9 @@ export class VoucherService {
get(id: string, type: string): Observable<Voucher> {
const endpoint = type.replace(/ /g, '-').toLowerCase();
return <Observable<Voucher>>(
this.http
.get<Voucher>(`${url}/${endpoint}/${id}`)
.pipe(catchError(this.log.handleError(serviceName, 'Get Voucher')))
);
return this.http
.get<Voucher>(`${url}/${endpoint}/${id}`)
.pipe(catchError(this.log.handleError(serviceName, 'Get Voucher'))) as Observable<Voucher>;
}
getOfType(type: string, account?: string): Observable<Voucher> {
@ -50,36 +44,30 @@ export class VoucherService {
// eslint-disable-next-line @typescript-eslint/dot-notation
options = { params: new HttpParams().set('a', account) };
}
return <Observable<Voucher>>(
this.http
.get<Voucher>(`${url}/${endpoint}`, options)
.pipe(catchError(this.log.handleError(serviceName, 'Get Voucher of Type')))
);
return this.http
.get<Voucher>(`${url}/${endpoint}`, options)
.pipe(
catchError(this.log.handleError(serviceName, 'Get Voucher of Type')),
) as Observable<Voucher>;
}
getIncentive(date: string): Observable<Voucher> {
const options = { params: new HttpParams().set('d', date) };
return <Observable<Voucher>>(
this.http
.get<Voucher>(`${url}/incentive`, options)
.pipe(catchError(this.log.handleError(serviceName, 'Get Incentive')))
);
return this.http
.get<Voucher>(`${url}/incentive`, options)
.pipe(catchError(this.log.handleError(serviceName, 'Get Incentive'))) as Observable<Voucher>;
}
post(id: string): Observable<Voucher> {
return <Observable<Voucher>>(
this.http
.post<Voucher>(`${url}/post-voucher/${id}`, {})
.pipe(catchError(this.log.handleError(serviceName, 'Post Voucher')))
);
return this.http
.post<Voucher>(`${url}/post as Observable<Voucher>-voucher/${id}`, {})
.pipe(catchError(this.log.handleError(serviceName, 'Post Voucher'))) as Observable<Voucher>;
}
delete(id: string): Observable<Voucher> {
return <Observable<Voucher>>(
this.http
.delete<Voucher>(`${url}/delete/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'Delete Voucher')))
);
return this.http
.delete<Voucher>(`${url}/delete/${id}`)
.pipe(catchError(this.log.handleError(serviceName, 'Delete Voucher'))) as Observable<Voucher>;
}
saveOrUpdate(voucher: Voucher): Observable<Voucher> {
@ -100,11 +88,9 @@ export class VoucherService {
});
voucher.files = voucher.files.filter((x) => x.id);
fd.append('data', JSON.stringify(voucher));
return <Observable<Voucher>>(
this.http
.post<Voucher>(`${url}/${endpoint}`, fd)
.pipe(catchError(this.log.handleError(serviceName, 'Save Voucher')))
);
return this.http
.post<Voucher>(`${url}/${endpoint}`, fd)
.pipe(catchError(this.log.handleError(serviceName, 'Save Voucher'))) as Observable<Voucher>;
}
update(voucher: Voucher, endpoint: string): Observable<Voucher> {
@ -117,10 +103,8 @@ export class VoucherService {
});
voucher.files = voucher.files.filter((x) => x.id);
fd.append('data', JSON.stringify(voucher));
return <Observable<Voucher>>(
this.http
.put<Voucher>(`${url}/${endpoint}/${voucher.id}`, fd)
.pipe(catchError(this.log.handleError(serviceName, 'Update Voucher')))
);
return this.http
.put<Voucher>(`${url}/${endpoint}/${voucher.id}`, fd)
.pipe(catchError(this.log.handleError(serviceName, 'Update Voucher'))) as Observable<Voucher>;
}
}