feat(deltagare): Added deltagare list with data from api. Also adjusted mock-api to match the api. (TV-309)
Squashed commit of the following: commit 41560491305b61ba322fa653788411de6112cc7e Merge: a157e6903a2c7aAuthor: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Aug 18 07:23:35 2021 +0200 Merged develop and fixed conflicts commit a157e69d6b4b18c9b8a806c4bbbc264b8b311b67 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Aug 17 13:54:29 2021 +0200 Removed console.log commit 87a532eb63b9c68109a4f847cc9530a47a56b648 Merge: db2ff176d29baaAuthor: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Aug 17 13:52:54 2021 +0200 Merged develop and fixed conflicts commit db2ff1758218c651cadf93de8ce0c5034d6994d3 Merge: 588adee01dc4b3Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Aug 16 13:09:33 2021 +0200 Merged develop and fixed conflicts commit 588adee5b17aeefcaf526aabdde02ca975c9c031 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Aug 16 11:11:57 2021 +0200 Added deltagarlist commit a0c378a8221a5d363f56ee644b9728d873ae1ff1 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Aug 16 07:19:49 2021 +0200 Updates after PR commit 479df238c712e2e14829d33b468ece91332f81c8 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Aug 13 15:18:23 2021 +0200 Updated tolkbehov inside deltagare-card commit df95ae2a8afbcc78ba546472ae9c1db141d1e642 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Aug 13 15:14:27 2021 +0200 Updated deltagare-kort after discussion with UX
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { UnsubscribeDirective } from '@msfa-directives/unsubscribe.directive';
|
||||
import { SortOrder } from '@msfa-enums/sort-order.enum';
|
||||
import { environment } from '@msfa-environment';
|
||||
import { AvropResponse } from '@msfa-models/api/avrop.response.model';
|
||||
import { ContactInformationResponse } from '@msfa-models/api/contact-information.response.model';
|
||||
import { DeltagareCompactApiResponse } from '@msfa-models/api/deltagare.response.model';
|
||||
import { DisabilityResponse } from '@msfa-models/api/disability.response.model';
|
||||
import { DriversLicenseResponse } from '@msfa-models/api/drivers-license.response.model';
|
||||
import { EducationsResponse } from '@msfa-models/api/educations.response.model';
|
||||
@@ -13,12 +15,18 @@ import { WorkExperiencesResponse } from '@msfa-models/api/work-experiences.respo
|
||||
import { WorkLanguagesResponse } from '@msfa-models/api/work-languages.response.model';
|
||||
import { Avrop, mapAvropResponseToAvrop } from '@msfa-models/avrop.model';
|
||||
import { ContactInformation, mapResponseToContactInformation } from '@msfa-models/contact-information.model';
|
||||
import { Deltagare, DeltagareCompact, mapResponseToDeltagareCompact } from '@msfa-models/deltagare.model';
|
||||
import {
|
||||
Deltagare,
|
||||
DeltagareCompact,
|
||||
DeltagareCompactData,
|
||||
mapResponseToDeltagareCompact,
|
||||
} from '@msfa-models/deltagare.model';
|
||||
import { Disability, mapResponseToDisability } from '@msfa-models/disability.model';
|
||||
import { DriversLicense, mapResponseToDriversLicense } from '@msfa-models/drivers-license.model';
|
||||
import { Education, mapResponseToEducation } from '@msfa-models/education.model';
|
||||
import { errorToCustomError } from '@msfa-models/error/custom-error';
|
||||
import { HighestEducation, mapResponseToHighestEducation } from '@msfa-models/highest-education.model';
|
||||
import { Sort } from '@msfa-models/sort.model';
|
||||
import { mapResponseToWorkExperience, WorkExperience } from '@msfa-models/work-experience.model';
|
||||
import { ErrorService } from '@msfa-services/error.service';
|
||||
import { sortFromToDates } from '@msfa-utils/sort.util';
|
||||
@@ -33,6 +41,10 @@ const API_HEADERS = { headers: environment.api.headers };
|
||||
export class DeltagareService extends UnsubscribeDirective {
|
||||
private _apiBaseUrl = `${environment.api.url}/deltagare`;
|
||||
private _currentDeltagareId$ = new BehaviorSubject<string>(null);
|
||||
private _limit$ = new BehaviorSubject<number>(20);
|
||||
private _page$ = new BehaviorSubject<number>(1);
|
||||
private _sort$ = new BehaviorSubject<Sort<keyof DeltagareCompact>>({ key: 'fullName', order: SortOrder.ASC });
|
||||
public sort$: Observable<Sort<keyof DeltagareCompact>> = this._sort$.asObservable();
|
||||
|
||||
constructor(private httpClient: HttpClient, private errorService: ErrorService) {
|
||||
super();
|
||||
@@ -40,7 +52,7 @@ export class DeltagareService extends UnsubscribeDirective {
|
||||
this._currentDeltagareId$
|
||||
.pipe(
|
||||
filter(currentDeltagareId => !!currentDeltagareId),
|
||||
switchMap(currentDeltagareId => this.fetchDeltagare$(currentDeltagareId))
|
||||
switchMap(currentDeltagareId => this._fetchDeltagare$(currentDeltagareId))
|
||||
)
|
||||
.subscribe(deltagare => {
|
||||
this._deltagare$.next(deltagare);
|
||||
@@ -51,9 +63,47 @@ export class DeltagareService extends UnsubscribeDirective {
|
||||
private _deltagare$ = new BehaviorSubject<Deltagare>(null);
|
||||
public deltagare$: Observable<Deltagare> = this._deltagare$.asObservable();
|
||||
|
||||
public allDeltagare$: Observable<DeltagareCompact[]> = this.httpClient
|
||||
.get<{ data: AvropResponse[] }>(`${this._apiBaseUrl}`, { ...API_HEADERS })
|
||||
.pipe(map(({ data }) => data.map(deltagare => mapResponseToDeltagareCompact(deltagare))));
|
||||
public allDeltagareData$: Observable<DeltagareCompactData> = combineLatest([
|
||||
this._limit$,
|
||||
this._page$,
|
||||
this._sort$,
|
||||
]).pipe(switchMap(([limit, page, sort]) => this._fetchAllDeltagare$(limit, page, sort)));
|
||||
|
||||
public setSort(newSortKey: keyof DeltagareCompact): void {
|
||||
const currentSort = this._sort$.getValue();
|
||||
const order =
|
||||
currentSort.key === newSortKey && currentSort.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
|
||||
|
||||
this._sort$.next({ key: newSortKey, order });
|
||||
}
|
||||
|
||||
public setPage(page: number): void {
|
||||
this._page$.next(page);
|
||||
}
|
||||
|
||||
private _fetchAllDeltagare$(
|
||||
limit: number,
|
||||
page: number,
|
||||
sort: Sort<keyof DeltagareCompact>
|
||||
): Observable<DeltagareCompactData> {
|
||||
const params: { [param: string]: string | string[] } = {
|
||||
sort: sort.key as string,
|
||||
order: sort.order as string,
|
||||
limit: limit.toString(),
|
||||
page: page.toString(),
|
||||
};
|
||||
|
||||
return this.httpClient
|
||||
.get<DeltagareCompactApiResponse>(this._apiBaseUrl, {
|
||||
...API_HEADERS,
|
||||
params,
|
||||
})
|
||||
.pipe(
|
||||
map(({ data, meta }) => {
|
||||
return { data: data.map(deltagare => mapResponseToDeltagareCompact(deltagare)), meta };
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public setCurrentDeltagareId(currentDeltagareId: string): void {
|
||||
this._deltagare$.next(null);
|
||||
@@ -184,7 +234,7 @@ export class DeltagareService extends UnsubscribeDirective {
|
||||
// As TypeScript has some limitations regarding combining Observables this way,
|
||||
// we need to type it manually when exceeding 6 Observables inside a combineLatest.
|
||||
// Read: https://github.com/ReactiveX/rxjs/issues/3601#issuecomment-384711601
|
||||
public fetchDeltagare$(id: string): Observable<Deltagare> {
|
||||
private _fetchDeltagare$(id: string): Observable<Deltagare> {
|
||||
return combineLatest([
|
||||
this._fetchContactInformation$(id),
|
||||
this._fetchDriversLicense$(id),
|
||||
|
||||
Reference in New Issue
Block a user