feat(slutredovisning): Now fetching yrkesområden and yrkesgrupp from API. (TV-894)
Merge in TEA/mina-sidor-fa-web from feature/TV-894-fetch-yrken to develop Squashed commit of the following: commit f56d22a6c3a5fb47270f967456b58b8a02d8a863 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Nov 17 10:56:45 2021 +0100 Added get request to fetch yrkesområden from the API
This commit is contained in:
@@ -25,8 +25,8 @@ export class SlutredovisningFormService {
|
||||
|
||||
private _step2FormData$ = new BehaviorSubject<SlutredovisningStep2FormData | null>(null);
|
||||
|
||||
yrkesomraden$: Observable<Yrkesomrade[]> = this.slutredovisningApiService.yrken$.pipe(
|
||||
map(({ data }) => data.map(yo => mapResponseToYrkesomrade(yo))),
|
||||
yrkesomraden$: Observable<Yrkesomrade[]> = this.slutredovisningApiService.fetchYrken$().pipe(
|
||||
map(({ data }) => data.map(yrke => mapResponseToYrkesomrade(yrke))),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,4 @@
|
||||
export interface YrkesgruppResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
parentId: string;
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ import { YrkesgruppResponse } from './yrkesgrupp.response.model';
|
||||
export interface YrkesomradeResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
items: YrkesgruppResponse[];
|
||||
yrkesgrupper: YrkesgruppResponse[];
|
||||
}
|
||||
|
||||
@@ -3,11 +3,10 @@ import { YrkesgruppResponse } from './api/yrkesgrupp.response.model';
|
||||
export interface Yrkesgrupp {
|
||||
value: string;
|
||||
name: string;
|
||||
parentId: string;
|
||||
}
|
||||
|
||||
export function mapResponseToYrkesgrupp(data: YrkesgruppResponse): Yrkesgrupp {
|
||||
const { id, name, parentId } = data;
|
||||
const { id, name } = data;
|
||||
|
||||
return { value: id, name, parentId };
|
||||
return { value: id, name };
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ export interface Yrkesomrade {
|
||||
}
|
||||
|
||||
export function mapResponseToYrkesomrade(data: YrkesomradeResponse): Yrkesomrade {
|
||||
const { id, name, items } = data;
|
||||
const { id, name, yrkesgrupper } = data;
|
||||
|
||||
return { value: id, name, items: items.map(item => mapResponseToYrkesgrupp(item)) };
|
||||
return { value: id, name, items: yrkesgrupper.map(item => mapResponseToYrkesgrupp(item)) };
|
||||
}
|
||||
|
||||
export function yrkeToTextMap(yrkesomraden: Yrkesomrade[]): { [key: string]: string } {
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { YRKEN } from '@msfa-constants/yrken';
|
||||
import { ErrorType } from '@msfa-enums/error-type.enum';
|
||||
import { environment } from '@msfa-environment';
|
||||
import { SlutredovisningRequest } from '@msfa-models/api/slutredovisning.request.model';
|
||||
import { SlutredovisningResponse } from '@msfa-models/api/slutredovisning.response.model';
|
||||
import { YrkesomradeResponse } from '@msfa-models/api/yrkesomrade.response.model';
|
||||
import { CustomError } from '@msfa-models/error/custom-error';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class SlutredovisningApiService {
|
||||
private _apiBaseUrl = `${environment.api.url}/rapporter/slutredovisning`;
|
||||
private _apiBaseUrl = `${environment.api.url}/rapporter`;
|
||||
private _handlingarBaseUrl = `${environment.api.url}/handlingar`;
|
||||
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
|
||||
public yrken$: Observable<{ data: YrkesomradeResponse[] }> = of({ data: YRKEN });
|
||||
public fetchYrken$(): Observable<{ data: YrkesomradeResponse[] }> {
|
||||
return this.httpClient.get<{ data: YrkesomradeResponse[] }>(`${this._apiBaseUrl}/yrkesomraden`).pipe(
|
||||
catchError((error: Error) => {
|
||||
throw new CustomError({
|
||||
error,
|
||||
message: `Kunde inte hämta yrkesområden och yrkesgrupper.\n\n${error.message}`,
|
||||
type: ErrorType.API,
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public fetchSlutredovisning$(handlingId: string): Observable<{ data: SlutredovisningResponse }> {
|
||||
return this.httpClient.get<{ data: SlutredovisningResponse }>(
|
||||
@@ -28,7 +37,7 @@ export class SlutredovisningApiService {
|
||||
}
|
||||
|
||||
public submitSlutredovisning$(requestData: SlutredovisningRequest): Observable<void> {
|
||||
return this.httpClient.post<void>(`${this._apiBaseUrl}`, requestData).pipe(
|
||||
return this.httpClient.post<void>(`${this._apiBaseUrl}/slutredovisning`, requestData).pipe(
|
||||
catchError((error: Error) => {
|
||||
throw new CustomError({
|
||||
error,
|
||||
|
||||
Reference in New Issue
Block a user