Moved to Angular 6.0
---- Pending * Table width for the points column in incentive * Linting * keyboard navigation where it was used earlier * can remove the unused totals calculated serverside in productledger * spinner and loading bars * Activate Guard for Employee Function tabs * Progress for Fingerprint uploads * deleted reconcile and receipe features as they were not being used * focus the right control on component load
This commit is contained in:
73
overlord/src/app/employee/employee.service.ts
Normal file
73
overlord/src/app/employee/employee.service.ts
Normal file
@ -0,0 +1,73 @@
|
||||
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'})
|
||||
};
|
||||
|
||||
const url = '/api/Employee';
|
||||
const serviceName = 'EmployeeService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class EmployeeService {
|
||||
|
||||
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}`))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Employee[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Employee[]>>this.http.get<Employee[]>(url, options)
|
||||
.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'))
|
||||
);
|
||||
}
|
||||
|
||||
update(employee: Employee): Observable<Employee> {
|
||||
return <Observable<Employee>>this.http.put<Employee>(`${url}/${employee.id}`, employee, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(employee: Employee): Observable<Employee> {
|
||||
if (!employee.id) {
|
||||
return this.save(employee);
|
||||
} else {
|
||||
return this.update(employee);
|
||||
}
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Employee> {
|
||||
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, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'autocomplete'))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user