Moved from tslint to eslint as tslint was depreciated.
Added prettier and also prettied all the typescript files using prettier ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
@ -1,50 +1,52 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {Employee} from './employee';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Employee } from './employee';
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
|
||||
const url = '/api/employees';
|
||||
const serviceName = 'EmployeeService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class EmployeeService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<Employee> {
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Employee>>this.http.get<Employee>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Employee>>(
|
||||
this.http
|
||||
.get<Employee>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Employee[]> {
|
||||
return <Observable<Employee[]>>this.http.get<Employee[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
return <Observable<Employee[]>>(
|
||||
this.http
|
||||
.get<Employee[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
}
|
||||
|
||||
save(employee: Employee): Observable<Employee> {
|
||||
return <Observable<Employee>>this.http.post<Employee>(`${url}`, employee, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
return <Observable<Employee>>(
|
||||
this.http
|
||||
.post<Employee>(`${url}`, employee, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
|
||||
update(employee: Employee): Observable<Employee> {
|
||||
return <Observable<Employee>>this.http.put<Employee>(`${url}/${employee.id}`, employee, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
return <Observable<Employee>>(
|
||||
this.http
|
||||
.put<Employee>(`${url}/${employee.id}`, employee, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update')))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(employee: Employee): Observable<Employee> {
|
||||
@ -56,17 +58,19 @@ export class EmployeeService {
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Employee> {
|
||||
return <Observable<Employee>>this.http.delete<Employee>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
return <Observable<Employee>>(
|
||||
this.http
|
||||
.delete<Employee>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
|
||||
);
|
||||
}
|
||||
|
||||
autocomplete(term: string): Observable<Employee[]> {
|
||||
const options = {params: new HttpParams().set('q', term)};
|
||||
return <Observable<Employee[]>>this.http.get<Employee[]>(`${url}/query`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'autocomplete'))
|
||||
);
|
||||
const options = { params: new HttpParams().set('q', term) };
|
||||
return <Observable<Employee[]>>(
|
||||
this.http
|
||||
.get<Employee[]>(`${url}/query`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user