Merge branch 'next' into develop

This commit is contained in:
Erik Tiekstra
2021-09-29 08:04:02 +02:00
10 changed files with 89 additions and 68 deletions

View File

@@ -1,3 +1,24 @@
import { SortOrder } from '@msfa-enums/sort-order.enum';
import { DeltagareCompact } from '@msfa-models/deltagare.model';
import { EmployeeCompactResponse } from './employee.response.model';
export interface Params {
[param: string]: string | string[];
}
export interface PaginationParams {
page: number;
limit: number;
order: SortOrder;
search?: string;
}
export interface DeltagareParams extends PaginationParams {
sort: keyof DeltagareCompact;
onlyMyDeltagare: boolean;
}
export interface EmployeeParams extends PaginationParams {
sort: keyof EmployeeCompactResponse;
onlyEmployeesWithoutAuthorization: boolean;
}

View File

@@ -8,20 +8,19 @@ 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 { Params } from '@msfa-models/api/params.model';
import { DeltagareParams, Params } from '@msfa-models/api/params.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';
import { Avrop, mapAvropResponseToAvrop } from '@msfa-models/avrop.model';
import { ContactInformation, mapResponseToContactInformation } from '@msfa-models/contact-information.model';
import { DeltagareCompact, DeltagareCompactData, mapResponseToDeltagareCompact } from '@msfa-models/deltagare.model';
import { 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 { 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 { Sort } from '@msfa-models/sort.model';
import { mapResponseToWorkExperience, WorkExperience } from '@msfa-models/work-experience.model';
import { sortFromToDates } from '@msfa-utils/sort.util';
import { BehaviorSubject, Observable, of } from 'rxjs';
@@ -39,15 +38,11 @@ export class DeltagareApiService {
constructor(private httpClient: HttpClient) {}
public fetchAllDeltagare$(
limit: number,
page: number,
sort: Sort<keyof DeltagareCompact>,
onlyMyDeltagare?: boolean
): Observable<DeltagareCompactData> {
public fetchAllDeltagare$(deltagareParams: DeltagareParams): Observable<DeltagareCompactData> {
const { sort, order, limit, page, onlyMyDeltagare } = deltagareParams;
const params: Params = {
sort: sort.key as string,
order: sort.order as string,
sort,
order,
limit: limit.toString(),
page: page.toString(),
};

View File

@@ -10,7 +10,7 @@ import {
EmployeeResponse,
EmployeesDataResponse,
} from '@msfa-models/api/employee.response.model';
import { Params } from '@msfa-models/api/params.model';
import { EmployeeParams, Params } from '@msfa-models/api/params.model';
import {
Employee,
EmployeesData,
@@ -23,15 +23,6 @@ import { ErrorService } from '@msfa-services/error.service';
import { BehaviorSubject, combineLatest, Observable, of, throwError } from 'rxjs';
import { catchError, distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators';
interface EmployeeParams {
page: number;
limit: number;
sort: keyof EmployeeCompactResponse;
order: SortOrder;
search: string;
onlyEmployeesWithoutAuthorization: boolean;
}
@Injectable({
providedIn: 'root',
})
@@ -167,12 +158,10 @@ export class EmployeeService extends UnsubscribeDirective {
}
public setSort(sort: keyof EmployeeCompactResponse): void {
const currentParams = this._params$.getValue();
const currentSort = currentParams.sort;
const currentOrder = currentParams.order;
const order = currentSort === sort && currentOrder === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
const params = this._params$.getValue();
const order = params.sort === sort && params.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
this._params$.next({ ...this._params$.getValue(), sort, order });
this._params$.next({ ...params, sort, order });
}
public setPage(page: number): void {

View File

@@ -1,49 +1,51 @@
import { Injectable } from '@angular/core';
import { SortOrder } from '@msfa-enums/sort-order.enum';
import { DeltagareParams } from '@msfa-models/api/params.model';
import { DeltagareCompact, DeltagareCompactData } from '@msfa-models/deltagare.model';
import { Sort } from '@msfa-models/sort.model';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { BehaviorSubject, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { DeltagareApiService } from './api/deltagare.api.service';
@Injectable({
providedIn: 'root',
})
export class DeltagareService {
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();
private _onlyMyDeltagare$ = new BehaviorSubject<boolean>(false);
public onlyMyDeltagare$: Observable<boolean> = this._onlyMyDeltagare$.asObservable();
private _params$ = new BehaviorSubject<DeltagareParams>({
page: 1,
limit: 20,
sort: 'fullName',
order: SortOrder.ASC,
onlyMyDeltagare: false,
});
public sort$: Observable<Sort<keyof DeltagareCompact>> = this._params$.pipe(
map(({ sort, order }) => ({ key: sort, order }))
);
public onlyMyDeltagare$: Observable<boolean> = this._params$.pipe(map(({ onlyMyDeltagare }) => onlyMyDeltagare));
public showUnauthorizedError$: Observable<boolean> = this.deltagareApiService.showUnauthorizedError$;
public deltagareLoading$: Observable<boolean> = this.deltagareApiService.deltagareLoading$;
public allDeltagareData$: Observable<DeltagareCompactData> = combineLatest([
this._limit$,
this._page$,
this._sort$,
this._onlyMyDeltagare$,
]).pipe(
switchMap(([limit, page, sort, onlyMyDeltagare]) =>
this.deltagareApiService.fetchAllDeltagare$(limit, page, sort, onlyMyDeltagare)
)
public allDeltagareData$: Observable<DeltagareCompactData> = this._params$.pipe(
switchMap(params => this.deltagareApiService.fetchAllDeltagare$(params))
);
constructor(private deltagareApiService: DeltagareApiService) {}
public setSort(newSortKey: keyof DeltagareCompact): void {
const currentSort = this._sort$.getValue();
const order =
currentSort.key === newSortKey && currentSort.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
public setSort(sort: keyof DeltagareCompact): void {
const params = this._params$.getValue();
const order = params.sort === sort && params.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
this._sort$.next({ key: newSortKey, order });
this._params$.next({
...params,
sort,
order,
});
}
public setPage(page: number): void {
this._page$.next(page);
this._params$.next({ ...this._params$.getValue(), page });
}
public setOnlyMyDeltagare(value: boolean): void {
this._onlyMyDeltagare$.next(value);
this._params$.next({ ...this._params$.getValue(), onlyMyDeltagare: value, page: 1 });
}
}