feat(employee): Matched models to the API and adjusted mock-api. (TV-346)
Squashed commit of the following: commit 0f10a7864960cae47694212042f9d58053b05a0c Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Aug 18 14:13:15 2021 +0200 Changed tjanst and utforandeVerksamhet to plural commit 3ffe861d8721692d0b49b0f333f2f52186b23560 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Aug 18 12:26:43 2021 +0200 Updated fetching single employee in mock-api commit ae101885a90367b86b77faadaa171816aa2ffcaa Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Aug 18 12:23:28 2021 +0200 Changed models for employees and fixed mock-api
This commit is contained in:
@@ -4,14 +4,15 @@ import { ErrorType } from '@msfa-enums/error-type.enum';
|
||||
import { SortOrder } from '@msfa-enums/sort-order.enum';
|
||||
import { environment } from '@msfa-environment';
|
||||
import { EmployeeInviteMockApiResponse } from '@msfa-models/api/employee-invite.response.model';
|
||||
import { EmployeeResponse, EmployeesApiResponse } from '@msfa-models/api/employee.response.model';
|
||||
import { EmployeeInviteMockaData } from '@msfa-models/employee-invite-mock-data.model';
|
||||
import {
|
||||
Employee,
|
||||
EmployeeApiResponse,
|
||||
EmployeesApiResponse,
|
||||
EmployeeCompact,
|
||||
EmployeesData,
|
||||
mapEmployeeReponseToEmployee,
|
||||
mapEmployeeToEmployeeApiRequestData,
|
||||
mapEmployeeToRequestData,
|
||||
mapResponseToEmployee,
|
||||
mapResponseToEmployeeCompact,
|
||||
} from '@msfa-models/employee.model';
|
||||
import { Sort } from '@msfa-models/sort.model';
|
||||
import { BehaviorSubject, combineLatest, Observable, throwError } from 'rxjs';
|
||||
@@ -23,11 +24,11 @@ const API_HEADERS = { headers: environment.api.headers };
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class EmployeeService {
|
||||
private _apiUrl = `${environment.api.url}/employee`;
|
||||
private _apiUrl = `${environment.api.url}/users`;
|
||||
private _limit$ = new BehaviorSubject<number>(20);
|
||||
private _page$ = new BehaviorSubject<number>(1);
|
||||
private _sort$ = new BehaviorSubject<Sort<keyof Employee>>({ key: 'fullName', order: SortOrder.ASC });
|
||||
public sort$: Observable<Sort<keyof Employee>> = this._sort$.asObservable();
|
||||
private _sort$ = new BehaviorSubject<Sort<keyof EmployeeCompact>>({ key: 'fullName', order: SortOrder.ASC });
|
||||
public sort$: Observable<Sort<keyof EmployeeCompact>> = this._sort$.asObservable();
|
||||
private _searchFilter$ = new BehaviorSubject<string>('');
|
||||
private _onlyEmployeesWithoutAuthorization$ = new BehaviorSubject<boolean>(false);
|
||||
|
||||
@@ -46,7 +47,7 @@ export class EmployeeService {
|
||||
private _fetchEmployees$(
|
||||
limit: number,
|
||||
page: number,
|
||||
sort: Sort<keyof Employee>,
|
||||
sort: Sort<keyof EmployeeCompact>,
|
||||
searchFilter: string,
|
||||
onlyEmployeesWithoutAuthorization?: boolean
|
||||
): Observable<EmployeesData> {
|
||||
@@ -72,15 +73,15 @@ export class EmployeeService {
|
||||
})
|
||||
.pipe(
|
||||
map(({ data, meta }) => {
|
||||
return { data: data.map(employee => mapEmployeeReponseToEmployee(employee)), meta };
|
||||
return { data: data.map(employee => mapResponseToEmployeeCompact(employee)), meta };
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public fetchDetailedEmployeeData$(id: string): Observable<Employee> {
|
||||
return this.httpClient
|
||||
.get<EmployeeApiResponse>(`${this._apiUrl}/${id}`, { ...API_HEADERS })
|
||||
.pipe(map(result => mapEmployeeReponseToEmployee(result.data)));
|
||||
.get<{ data: EmployeeResponse }>(`${this._apiUrl}/${id}`, { ...API_HEADERS })
|
||||
.pipe(map(result => mapResponseToEmployee(result.data)));
|
||||
}
|
||||
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
@@ -93,7 +94,7 @@ export class EmployeeService {
|
||||
this._onlyEmployeesWithoutAuthorization$.next(value);
|
||||
}
|
||||
|
||||
public setSort(newSortKey: keyof Employee): void {
|
||||
public setSort(newSortKey: keyof EmployeeCompact): void {
|
||||
const currentSort = this._sort$.getValue();
|
||||
const order =
|
||||
currentSort.key === newSortKey && currentSort.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
|
||||
@@ -106,17 +107,15 @@ export class EmployeeService {
|
||||
}
|
||||
|
||||
public postNewEmployee(employeeData: Employee): Observable<string> {
|
||||
return this.httpClient
|
||||
.post<{ id: string }>(this._apiUrl, mapEmployeeToEmployeeApiRequestData(employeeData), API_HEADERS)
|
||||
.pipe(
|
||||
map(({ id }) => id),
|
||||
catchError(error => throwError({ message: error as string, type: ErrorType.API }))
|
||||
);
|
||||
return this.httpClient.post<{ id: string }>(this._apiUrl, mapEmployeeToRequestData(employeeData), API_HEADERS).pipe(
|
||||
map(({ id }) => id),
|
||||
catchError(error => throwError({ message: error as string, type: ErrorType.API }))
|
||||
);
|
||||
}
|
||||
|
||||
postEmployeeInvitation(email: string): Observable<EmployeeInviteMockaData> {
|
||||
public postEmployeeInvitation(email: string): Observable<EmployeeInviteMockaData> {
|
||||
return this.httpClient
|
||||
.post<{ data: EmployeeInviteMockApiResponse }>('http://localhost:8000/invites', { email }, API_HEADERS)
|
||||
.post<{ data: EmployeeInviteMockApiResponse }>(`${this._apiUrl}/invite`, { email }, API_HEADERS)
|
||||
.pipe(
|
||||
take(1),
|
||||
map(res => res.data),
|
||||
|
||||
Reference in New Issue
Block a user