Added work-experience to deltagare service

This commit is contained in:
Erik Tiekstra
2021-08-02 08:39:23 +02:00
parent 3a6d09110c
commit cbe41ab74c
4 changed files with 35 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
import { formatToIsoDate } from '@dafa-utils/format-to-iso-date.util';
import { EducationResponse } from './api/education.response.model';
export interface Education {
@@ -15,7 +16,7 @@ export function mapResponseToEducation(data: EducationResponse): Education {
education: utbildning,
description: beskrivning,
organizer: anordnare,
dateFrom: period_from,
dateTo: period_tom,
dateFrom: formatToIsoDate(period_from),
dateTo: formatToIsoDate(period_tom),
};
}

View File

@@ -1,3 +1,4 @@
import { formatToIsoDate } from '@dafa-utils/format-to-iso-date.util';
import { WorkExperienceResponse } from './api/work-experience.response.model';
export interface WorkExperience {
@@ -15,7 +16,7 @@ export function mapResponseToWorkExperience(data: WorkExperienceResponse): WorkE
profession: yrke,
description: beskrivning,
employer: arbetsgivare,
dateFrom: period_from,
dateTo: period_tom,
dateFrom: formatToIsoDate(period_from),
dateTo: formatToIsoDate(period_tom),
};
}

View File

@@ -18,7 +18,7 @@ import { Education, mapResponseToEducation } from '@dafa-models/education.model'
import { HighestEducation, mapResponseToHighestEducation } from '@dafa-models/highest-education.model';
import { mapResponseToWorkExperience, WorkExperience } from '@dafa-models/work-experience.model';
import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { map, tap } from 'rxjs/operators';
const API_HEADERS = { headers: environment.api.headers };
@@ -80,10 +80,11 @@ export class DeltagareService {
}
private _fetchDisabilities$(id: string): Observable<Disability[]> {
return this.httpClient
.get<DisabilityResponse[]>(`${this._apiBaseUrl}/work/disability/${id}`, { ...API_HEADERS })
.get<DisabilityResponse[][]>(`${this._apiBaseUrl}/work/disability/${id}`, { ...API_HEADERS })
.pipe(
tap(response => console.log(response)),
map(response =>
response ? response.map(funktionsnedsattning => mapResponseToDisability(funktionsnedsattning)) : []
response ? response[0].map(funktionsnedsattning => mapResponseToDisability(funktionsnedsattning)) : []
)
);
}
@@ -102,7 +103,7 @@ export class DeltagareService {
// }
private _fetchWorkExperiences$(id: string): Observable<WorkExperience[]> {
return this.httpClient
.get<{ data: WorkExperiencesResponse }>(`${this._apiBaseUrl}/work/${id}`, { ...API_HEADERS })
.get<{ data: WorkExperiencesResponse }>(`${this._apiBaseUrl}/work/experience/${id}`, { ...API_HEADERS })
.pipe(
map(response =>
response.data.arbetslivserfarenheter
@@ -133,16 +134,27 @@ export class DeltagareService {
this._fetchTranslator$(id),
this._fetchWorkLanguages$(id),
this._fetchDisabilities$(id),
this._fetchWorkExperiences$(id),
]).pipe(
map(
([contactInformation, driversLicense, highestEducation, educations, translator, workLanguages, disabilities]: [
([
contactInformation,
driversLicense,
highestEducation,
educations,
translator,
workLanguages,
disabilities,
workExperiences,
]: [
ContactInformation,
DriversLicense,
HighestEducation,
Education[],
string,
string[],
Disability[]
Disability[],
WorkExperience[]
]) => ({
id,
...contactInformation,
@@ -152,6 +164,7 @@ export class DeltagareService {
translator,
workLanguages,
disabilities,
workExperiences,
})
)
);

View File

@@ -0,0 +1,10 @@
// Takes either 6 or 8 characters string (YYYYMMDD) and formats it to ISO standard (YYYY-MM-DD).
export function formatToIsoDate(date: string): string {
if (date.length === 6) {
return `${date.substring(0, 4)}-${date.substring(4)}`;
} else if (date.length === 8) {
return `${date.substring(0, 4)}-${date.substring(4, 6)}-${date.substring(6)}`;
}
return date;
}