Added Pega API

This commit is contained in:
Erik Tiekstra
2021-05-04 15:47:03 +02:00
parent 067b25c3aa
commit 9f5570ca6a
12 changed files with 129 additions and 28 deletions

View File

@@ -82,6 +82,14 @@
"maximumError": "10kb" "maximumError": "10kb"
} }
] ]
},
"pega": {
"fileReplacements": [
{
"replace": "apps/dafa-web/src/environments/environment.ts",
"with": "apps/dafa-web/src/environments/environment.pega.ts"
}
]
} }
} }
}, },
@@ -94,6 +102,9 @@
"configurations": { "configurations": {
"production": { "production": {
"browserTarget": "dafa-web:build:production" "browserTarget": "dafa-web:build:production"
},
"pega": {
"browserTarget": "dafa-web:build:pega"
} }
} }
}, },

View File

@@ -1,5 +1,6 @@
import { Agency } from '@dafa-models/agency.model'; import { Agency } from '@dafa-models/agency.model';
import { Participant } from './participant.model'; import { Participant } from './participant.model';
import { EmployeeReponse } from './pega/employee-reponse.model';
export interface Employee { export interface Employee {
id: string; id: string;
@@ -25,3 +26,18 @@ export interface EmployeeDetail extends Employee {
agencies: Agency[]; agencies: Agency[];
participants: Participant[]; participants: Participant[];
} }
export function mapEmployeeReponseToEmployee(data: EmployeeReponse): Employee {
const names = data.pyUserName.split(' ');
return {
id: data.pyUserIdentifier,
employeeId: data.pyUserIdentifier,
lastName: names.pop() || 'Doe',
firstName: names.join(' ') || 'John',
utforandeverksamhet: '',
active: true,
service: '',
fullName: data.pyUserName,
};
}

View File

@@ -0,0 +1,10 @@
export interface EmployeeReponse {
pxObjClass: string;
pyAccessGroup: string;
pyLabel: string;
pyPosition: string;
pyReportTo: string;
pyUserIdentifier: string;
pyUserName: string;
pyWorkGroup: string;
}

View File

@@ -52,7 +52,7 @@
[afCurrentResultEnd]="currentResultEnd" [afCurrentResultEnd]="currentResultEnd"
[afTotalResults]="employees.length" [afTotalResults]="employees.length"
(afOnPageChange)="handlePagination($event.detail)" (afOnPageChange)="handlePagination($event.detail)"
af-result-name="deltagare" af-result-name="medarbetare"
> >
</digi-navigation-pagination> </digi-navigation-pagination>
</div> </div>

View File

@@ -15,8 +15,8 @@
<form class="employees__search-wrapper" (ngSubmit)="handleSearchSubmit()"> <form class="employees__search-wrapper" (ngSubmit)="handleSearchSubmit()">
<digi-form-input-search <digi-form-input-search
af-label="Sök kunder" af-label="Sök personal"
af-label-description="Sök på namn eller ärendenummer" af-label-description="Sök på namn"
(afOnInput)="handleSearchInput($event)" (afOnInput)="handleSearchInput($event)"
></digi-form-input-search> ></digi-form-input-search>
</form> </form>

View File

@@ -10,7 +10,7 @@
<form class="participants__search-wrapper" (ngSubmit)="handleSearchSubmit()"> <form class="participants__search-wrapper" (ngSubmit)="handleSearchSubmit()">
<digi-form-input-search <digi-form-input-search
af-label="Sök kunder" af-label="Sök deltagare"
af-label-description="Sök på namn eller ärendenummer" af-label-description="Sök på namn eller ärendenummer"
(afOnInput)="handleSearchInput($event)" (afOnInput)="handleSearchInput($event)"
></digi-form-input-search> ></digi-form-input-search>

View File

@@ -0,0 +1,69 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '@dafa-environment';
import { Employee, EmployeeDetail } from '@dafa-models/employee.model';
import { SortBy } from '@dafa-models/sort-by.model';
import { sort } from '@dafa-utils/sort.util';
import { BehaviorSubject, combineLatest, Observable, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
function filterEmployees(employees: Employee[], searchFilter: string): Employee[] {
return employees.filter(person => {
const searchValueExistsInName = person.fullName.toLowerCase().includes(searchFilter.toLowerCase());
return searchValueExistsInName;
});
}
@Injectable({
providedIn: 'root',
})
export class EmployeeService {
private _employeesApiUrl = `${environment.apiBase}/employees`;
private _allEmployees$: Observable<Employee[]> = this.httpClient.get<Employee[]>(this._employeesApiUrl, {
params: { _embed: 'participants' },
});
private _employeesSortBy$ = new BehaviorSubject<SortBy | null>({ key: 'fullName', reverse: false });
public employeesSortBy$: Observable<SortBy> = this._employeesSortBy$.asObservable();
private _searchFilter$ = new BehaviorSubject<string>('');
public searchFilter$: Observable<string> = this._searchFilter$.asObservable();
private _filteredEmployees$: Observable<Employee[]> = combineLatest([this._allEmployees$, this._searchFilter$]).pipe(
map(([employees, searchFilter]) => filterEmployees(employees, searchFilter))
);
public filteredEmployees$: Observable<Employee[]> = combineLatest([
this._filteredEmployees$,
this._employeesSortBy$,
]).pipe(
map(([employees, sortBy]) => {
return sortBy ? sort(employees, sortBy) : employees;
})
);
constructor(private httpClient: HttpClient) {}
public getDetailedEmployeeData(id: string): Observable<Employee> {
return this.httpClient.get<Employee>(`${this._employeesApiUrl}/${id}`, { params: { _embed: 'participants' } });
}
public setSearchFilter(value: string) {
this._searchFilter$.next(value);
}
public setEmployeesSortKey(key: keyof Employee) {
const currentSortBy = this._employeesSortBy$.getValue();
const reverse = currentSortBy?.key === key ? !currentSortBy.reverse : false;
this._employeesSortBy$.next({ key, reverse });
}
public createAccount(employeesData: EmployeeDetail): Observable<string> {
return this.httpClient.post<EmployeeDetail>(this._employeesApiUrl, employeesData).pipe(
map(data => data.id),
catchError(error => {
return throwError(error);
})
);
}
}

View File

@@ -1,28 +1,26 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { environment } from '@dafa-environment'; import { environment } from '@dafa-environment';
import { Employee, EmployeeDetail } from '@dafa-models/employee.model'; import { Employee, EmployeeDetail, mapEmployeeReponseToEmployee } from '@dafa-models/employee.model';
import { SortBy } from '@dafa-models/sort-by.model'; import { SortBy } from '@dafa-models/sort-by.model';
import { sort } from '@dafa-utils/sort.util'; import { sort } from '@dafa-utils/sort.util';
import { BehaviorSubject, combineLatest, Observable, throwError } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; import { catchError, map } from 'rxjs/operators';
function filterEmployees(employees: Employee[], searchFilter: string): Employee[] { function filterEmployees(employees: Employee[], searchFilter: string): Employee[] {
return employees.filter(person => { return employees.filter(person => person.fullName.toLowerCase().includes(searchFilter.toLowerCase()));
const searchValueExistsInName = person.fullName.toLowerCase().includes(searchFilter.toLowerCase());
return searchValueExistsInName;
});
} }
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class EmployeeService { export class EmployeeService {
private _employeesApiUrl = `${environment.apiBase}/employees`; private _employeesApiUrl = `${environment.apiBase}/D_pxOperatorsList`;
private _allEmployees$: Observable<Employee[]> = this.httpClient.get<Employee[]>(this._employeesApiUrl, { private _allEmployees$: Observable<Employee[]> = this.httpClient
params: { _embed: 'participants' }, .get<any>(this._employeesApiUrl, {
}); headers: environment.apiHeaders,
})
.pipe(map(({ pxResults }) => pxResults.map(result => mapEmployeeReponseToEmployee(result))));
private _employeesSortBy$ = new BehaviorSubject<SortBy | null>({ key: 'fullName', reverse: false }); private _employeesSortBy$ = new BehaviorSubject<SortBy | null>({ key: 'fullName', reverse: false });
public employeesSortBy$: Observable<SortBy> = this._employeesSortBy$.asObservable(); public employeesSortBy$: Observable<SortBy> = this._employeesSortBy$.asObservable();

View File

@@ -0,0 +1,7 @@
export const environment = {
production: false,
apiBase: 'https://dafa-utv.tocp.arbetsformedlingen.se/prweb/api/v1/data',
apiHeaders: {
Authorization: 'Basic dGVzdHVzZXIxOmRhZmFAMTIz', // user: testuser1, password: dafa@123
},
};

View File

@@ -1,17 +1,5 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = { export const environment = {
production: false, production: false,
apiBase: '/api', apiBase: '/api',
apiHeaders: {},
}; };
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.

View File

@@ -97,7 +97,7 @@ pipeline {
echo '### Building application... ###' echo '### Building application... ###'
sh ''' sh '''
npm run build:dafa npm run build:pega
cp nginx/nginx.conf ${NGINX_PATH} cp nginx/nginx.conf ${NGINX_PATH}
#cp -r nginx/* ${NGINX_PATH} #cp -r nginx/* ${NGINX_PATH}

View File

@@ -12,8 +12,10 @@
"nx": "nx", "nx": "nx",
"start": "ng serve", "start": "ng serve",
"start:dafa": "ng serve dafa-web", "start:dafa": "ng serve dafa-web",
"start:pega": "ng serve dafa-web --configuration pega",
"build": "ng build", "build": "ng build",
"build:dafa": "ng build dafa-web", "build:dafa": "ng build dafa-web",
"build:pega": "ng build dafa-web --configuration pega",
"test": "ng test", "test": "ng test",
"test:dafa": "ng test dafa-web", "test:dafa": "ng test dafa-web",
"lint": "nx workspace-lint && ng lint", "lint": "nx workspace-lint && ng lint",