feat(deltagare): Added list with reports. (TV-732)
Squashed commit of the following: commit 225a54c520c3cceaccd348b587df83e8e2050e2d Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Oct 6 15:00:30 2021 +0200 Added error-handling to reports fetch commit 876e8d1a338f8f910086868083bb0b4d61fcff63 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Oct 6 14:50:51 2021 +0200 Added pagination preparation commit 5e90bc4c0b6079852c05628f1b7fa79cc7f2bc9a Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Oct 6 14:32:46 2021 +0200 Added reports list to reports tab
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
export enum ReportType {
|
||||
FRANVARO = 'franvaro',
|
||||
AVVIKELSE = 'avvikelse',
|
||||
GemensamPlanering = 'Gemensam planering',
|
||||
Franvaro = 'Frånvaro',
|
||||
Avvikelse = 'Avvikelse',
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { ReportType } from '@msfa-enums/report-type.enum';
|
||||
import { PaginationMeta } from '@msfa-models/pagination-meta.model';
|
||||
import { Report } from '@msfa-models/reports.model';
|
||||
|
||||
export interface ReportResponse {
|
||||
data: Report[];
|
||||
id: string;
|
||||
genomforandeReferens: string;
|
||||
typAvRapport: ReportType;
|
||||
inskickadDatum: string;
|
||||
statusRapport: string;
|
||||
ciamUserId: string;
|
||||
}
|
||||
export interface ReportsDataResponse {
|
||||
data: ReportResponse[];
|
||||
meta: PaginationMeta;
|
||||
}
|
||||
|
||||
export interface ReportsApiResponseData {
|
||||
type: string;
|
||||
sendDate: Date;
|
||||
status: string;
|
||||
}
|
||||
|
||||
29
apps/mina-sidor-fa/src/app/shared/models/report.model.ts
Normal file
29
apps/mina-sidor-fa/src/app/shared/models/report.model.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ReportType } from '@msfa-enums/report-type.enum';
|
||||
import { ReportResponse } from './api/report.response.model';
|
||||
import { PaginationMeta } from './pagination-meta.model';
|
||||
|
||||
export interface Report {
|
||||
id: string;
|
||||
genomforandeReferens: string;
|
||||
type: string;
|
||||
date: Date;
|
||||
status: string;
|
||||
ciamUserId: string;
|
||||
}
|
||||
|
||||
export interface ReportsData {
|
||||
data: Report[];
|
||||
meta: PaginationMeta;
|
||||
}
|
||||
|
||||
export function mapResponseToReport(data: ReportResponse): Report {
|
||||
const { id, genomforandeReferens, typAvRapport, inskickadDatum, statusRapport, ciamUserId } = data;
|
||||
return {
|
||||
id,
|
||||
genomforandeReferens,
|
||||
type: (ReportType[typAvRapport] as string) || 'Okänd',
|
||||
date: new Date(inskickadDatum),
|
||||
status: statusRapport,
|
||||
ciamUserId,
|
||||
};
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { ReportsApiResponseData } from './api/report.response.model';
|
||||
import { PaginationMeta } from './pagination-meta.model';
|
||||
|
||||
export interface Report {
|
||||
type: string;
|
||||
sendDate: Date;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface ReportsData {
|
||||
data: Report[];
|
||||
meta: PaginationMeta;
|
||||
}
|
||||
|
||||
export function mapReportsResponseToReport(data: ReportsApiResponseData): Report {
|
||||
const { type, sendDate, status } = data;
|
||||
return {
|
||||
type,
|
||||
sendDate,
|
||||
status
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ 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';
|
||||
import { HighestEducationResponse } from '@msfa-models/api/highest-education.response.model';
|
||||
import { DeltagareParams, Params } from '@msfa-models/api/params.model';
|
||||
import { DeltagareParams, PaginationParams, Params } from '@msfa-models/api/params.model';
|
||||
import { ReportsDataResponse } from '@msfa-models/api/report.response.model';
|
||||
import { TranslatorResponse } from '@msfa-models/api/translator.response.model';
|
||||
import { WorkExperiencesResponse } from '@msfa-models/api/work-experiences.response.model';
|
||||
import { WorkLanguagesResponse } from '@msfa-models/api/work-languages.response.model';
|
||||
@@ -20,7 +21,7 @@ import { DriversLicense, mapResponseToDriversLicense } from '@msfa-models/driver
|
||||
import { Education, mapResponseToEducation } from '@msfa-models/education.model';
|
||||
import { CustomError, errorToCustomError } from '@msfa-models/error/custom-error';
|
||||
import { HighestEducation, mapResponseToHighestEducation } from '@msfa-models/highest-education.model';
|
||||
import { ReportsData } from '@msfa-models/reports.model';
|
||||
import { mapResponseToReport, ReportsData } from '@msfa-models/report.model';
|
||||
import { mapResponseToWorkExperience, WorkExperience } from '@msfa-models/work-experience.model';
|
||||
import { sortFromToDates } from '@msfa-utils/sort.util';
|
||||
import { BehaviorSubject, Observable, of } from 'rxjs';
|
||||
@@ -31,6 +32,7 @@ import { catchError, map } from 'rxjs/operators';
|
||||
})
|
||||
export class DeltagareApiService {
|
||||
private _apiBaseUrl = `${environment.api.url}/deltagare`;
|
||||
private _apiReportUrl = `${environment.api.url}/handlingar`;
|
||||
private _deltagareLoading$ = new BehaviorSubject<boolean>(false);
|
||||
public deltagareLoading$: Observable<boolean> = this._deltagareLoading$.asObservable();
|
||||
private _showUnauthorizedError$ = new BehaviorSubject<boolean>(false);
|
||||
@@ -75,28 +77,24 @@ export class DeltagareApiService {
|
||||
);
|
||||
}
|
||||
|
||||
public fetchReports$(limit: number, page: number, genomforandeReferens: number): Observable<ReportsData> {
|
||||
return of({ data: [], meta: null });
|
||||
public fetchReports$(genomforandeReferens: number, paginationParams: PaginationParams): Observable<ReportsData> {
|
||||
const { page, limit } = paginationParams;
|
||||
const params: { [param: string]: string | string[] } = {
|
||||
genomforandeReferens: genomforandeReferens.toString(),
|
||||
page: page.toString(),
|
||||
limit: limit.toString(),
|
||||
};
|
||||
|
||||
// TODO: When the API/Mock-API has implemented the endpoint, we can remove use following code
|
||||
// to make API-requests.
|
||||
|
||||
// const params: { [param: string]: string | string[] } = {
|
||||
// id: genomforandeReferens.toString(),
|
||||
// limit: limit.toString(),
|
||||
// page: page.toString(),
|
||||
// };
|
||||
|
||||
// return this.httpClient
|
||||
// .get<ReportResponse>(`${this._apiBaseUrl}/report`, {
|
||||
// params,
|
||||
// })
|
||||
// .pipe(
|
||||
// map(({ data, meta }) => {
|
||||
// data.sort((reportA, reportB) => (+reportA.sendDate < +reportB.sendDate ? 1 : -1));
|
||||
// return { data: data.map(report => mapReportsResponseToReport(report)), meta };
|
||||
// })
|
||||
// );
|
||||
return this.httpClient
|
||||
.get<ReportsDataResponse>(`${this._apiReportUrl}`, { params })
|
||||
.pipe(
|
||||
map(({ data, meta }) => ({ data: data.map(report => mapResponseToReport(report)), meta })),
|
||||
catchError((error: Error) => {
|
||||
throw new CustomError(
|
||||
errorToCustomError({ ...error, message: `Kunde inte hämta rapporter.\n\n${error.message}` })
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public fetchContactInformation$(genomforandeReferens: number): Observable<ContactInformation> {
|
||||
|
||||
Reference in New Issue
Block a user