diff --git a/apps/dafa-web/src/app/pages/avrop/components/avrop-table/avrop-table-row/avrop-table-row.component.html b/apps/dafa-web/src/app/pages/avrop/components/avrop-table/avrop-table-row/avrop-table-row.component.html index 51aabc0..ecf6f3e 100644 --- a/apps/dafa-web/src/app/pages/avrop/components/avrop-table/avrop-table-row/avrop-table-row.component.html +++ b/apps/dafa-web/src/app/pages/avrop/components/avrop-table/avrop-table-row/avrop-table-row.component.html @@ -28,13 +28,13 @@
Startdatum: - {{deltagare?.startDate | date: 'yyyy-MM-dd'}} +
Slutdatum: - {{deltagare?.endDate | date: 'yyyy-MM-dd'}} +
@@ -42,7 +42,7 @@
Språkstöd/Tolk: - {{deltagare?.sprakstod.beskrivning + '/' + deltagare?.tolkbehov.beskrivning}} + {{deltagare?.sprakstod + '/' + deltagare?.tolkbehov}}
diff --git a/apps/dafa-web/src/app/shared/models/api/authentication.response.model.ts b/apps/dafa-web/src/app/shared/models/api/authentication.response.model.ts new file mode 100644 index 0000000..bd8acda --- /dev/null +++ b/apps/dafa-web/src/app/shared/models/api/authentication.response.model.ts @@ -0,0 +1,8 @@ +export interface AuthenticationResponse { + id: string; + access_token: string; + scope: string; + id_token: string; + token_type: string; + expires_in: number; +} diff --git a/apps/dafa-web/src/app/shared/models/api/organization.response.model.ts b/apps/dafa-web/src/app/shared/models/api/organization.response.model.ts new file mode 100644 index 0000000..4dcf4a6 --- /dev/null +++ b/apps/dafa-web/src/app/shared/models/api/organization.response.model.ts @@ -0,0 +1,4 @@ +export interface OrganizationResponse { + name: string; + organizationnumber: string; +} diff --git a/apps/dafa-web/src/app/shared/models/api/user-info.response.model.ts b/apps/dafa-web/src/app/shared/models/api/user-info.response.model.ts new file mode 100644 index 0000000..8a8c6d7 --- /dev/null +++ b/apps/dafa-web/src/app/shared/models/api/user-info.response.model.ts @@ -0,0 +1,6 @@ +export interface UserInfoResponse { + id: string; + firstName: string; + lastName: string; + roles: string[]; +} diff --git a/apps/dafa-web/src/app/shared/models/authentication.model.ts b/apps/dafa-web/src/app/shared/models/authentication.model.ts index 5629677..937356c 100644 --- a/apps/dafa-web/src/app/shared/models/authentication.model.ts +++ b/apps/dafa-web/src/app/shared/models/authentication.model.ts @@ -1,18 +1,11 @@ -export interface AuthenticationResult { +import { AuthenticationResponse } from './api/authentication.response.model'; + +export interface Authentication { idToken: string; expiresIn: number; } -export interface AuthenticationApiResponse { - id: string; - access_token: string; - scope: string; - id_token: string; - token_type: string; - expires_in: number; -} - -export function mapAuthApiResponseToAuthenticationResult(data: AuthenticationApiResponse): AuthenticationResult { +export function mapAuthApiResponseToAuthenticationResult(data: AuthenticationResponse): Authentication { const { id_token, expires_in } = data; return { idToken: id_token, diff --git a/apps/dafa-web/src/app/shared/models/environment.model.ts b/apps/dafa-web/src/app/shared/models/environment.model.ts new file mode 100644 index 0000000..e710ae6 --- /dev/null +++ b/apps/dafa-web/src/app/shared/models/environment.model.ts @@ -0,0 +1,10 @@ +export interface Environment { + environment: 'api' | 'local' | 'prod'; + clientId: string; + loginUrl: string; + production: boolean; + api: { + url: string; + headers: { [key: string]: string }; + }; +} diff --git a/apps/dafa-web/src/app/shared/models/organization.model.ts b/apps/dafa-web/src/app/shared/models/organization.model.ts index f4c33e6..979064c 100644 --- a/apps/dafa-web/src/app/shared/models/organization.model.ts +++ b/apps/dafa-web/src/app/shared/models/organization.model.ts @@ -1,12 +1,15 @@ +import { OrganizationResponse } from './api/organization.response.model'; + export interface Organization { - id: string; name: string; - kaNumber: number; - address: { - street: string; - houseNumber: number; - postalCode: string; - city: string; - kommun: string; + organizationNumber: string; +} + +export function mapResponseToOrganization(data: OrganizationResponse): Organization { + const { name, organizationnumber } = data; + + return { + name, + organizationNumber: organizationnumber, }; } diff --git a/apps/dafa-web/src/app/shared/models/user-info.model.ts b/apps/dafa-web/src/app/shared/models/user-info.model.ts new file mode 100644 index 0000000..7b8ab0d --- /dev/null +++ b/apps/dafa-web/src/app/shared/models/user-info.model.ts @@ -0,0 +1,21 @@ +import { UserInfoResponse } from './api/user-info.response.model'; + +export interface UserInfo { + id: string; + firstName: string; + lastName: string; + fullName: string; + roles: string[]; +} + +export function mapResponseToUserInfo(data: UserInfoResponse): UserInfo { + const { id, firstName, lastName, roles } = data; + + return { + id, + firstName, + lastName, + fullName: `${firstName} ${lastName}`, + roles, + }; +} diff --git a/apps/dafa-web/src/app/shared/models/user.model.ts b/apps/dafa-web/src/app/shared/models/user.model.ts index 5c849b4..ba30831 100644 --- a/apps/dafa-web/src/app/shared/models/user.model.ts +++ b/apps/dafa-web/src/app/shared/models/user.model.ts @@ -1,39 +1,21 @@ -import { Authorization } from './authorization.model'; -import { Organization } from './organization.model'; +import { OrganizationResponse } from './api/organization.response.model'; +import { UserInfoResponse } from './api/user-info.response.model'; +import { mapResponseToOrganization, Organization } from './organization.model'; +import { UserInfo } from './user-info.model'; -export interface User { - id: string; - firstName: string; - lastName: string; - fullName: string; - ssn: string; +export interface User extends UserInfo { organizations: Organization[]; - authorizations: Authorization[]; } -export interface UserApiResponse { - data: UserApiResponseData; -} - -export interface UserApiResponseData { - id: string; - firstName: string; - lastName: string; - ssn: string; - organizations: Organization[]; - authorizations: Authorization[]; -} - -export function mapUserApiResponseToUser(data: UserApiResponseData): User { - const { id, firstName, lastName, ssn, organizations, authorizations } = data; +export function mapUserApiResponseToUser(userInfo: UserInfoResponse, organizations: OrganizationResponse[]): User { + const { id, firstName, lastName, roles } = userInfo; return { id, firstName, lastName, fullName: `${firstName} ${lastName}`, - ssn, - organizations, - authorizations, + roles, + organizations: organizations ? organizations.map(organization => mapResponseToOrganization(organization)) : [], }; } diff --git a/apps/dafa-web/src/app/shared/services/api/authentication.service.ts b/apps/dafa-web/src/app/shared/services/api/authentication.service.ts index 9d21673..fde0b5d 100644 --- a/apps/dafa-web/src/app/shared/services/api/authentication.service.ts +++ b/apps/dafa-web/src/app/shared/services/api/authentication.service.ts @@ -1,11 +1,8 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { environment } from '@dafa-environment'; -import { - AuthenticationApiResponse, - AuthenticationResult, - mapAuthApiResponseToAuthenticationResult, -} from '@dafa-models/authentication.model'; +import { AuthenticationResponse } from '@dafa-models/api/authentication.response.model'; +import { Authentication, mapAuthApiResponseToAuthenticationResult } from '@dafa-models/authentication.model'; import { add, isBefore } from 'date-fns'; import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { map, tap } from 'rxjs/operators'; @@ -33,7 +30,7 @@ export class AuthenticationService { return `${environment.api.url}/auth/token?accessCode=${code}`; } - private _setSession(authenticationResult: AuthenticationResult): void { + private _setSession(authenticationResult: Authentication): void { const expiresAt = add(new Date(), { seconds: authenticationResult.expiresIn }); this._token$.next(authenticationResult.idToken); @@ -42,11 +39,14 @@ export class AuthenticationService { localStorage.setItem('expires_at', JSON.stringify(expiresAt.valueOf())); } - login$(authorizationCodeFromCiam: string): Observable { + login$(authorizationCodeFromCiam: string): Observable { return this.httpClient - .get(AuthenticationService._authTokenApiUrl(authorizationCodeFromCiam), API_HEADERS) + .get<{ data: AuthenticationResponse }>( + AuthenticationService._authTokenApiUrl(authorizationCodeFromCiam), + API_HEADERS + ) .pipe( - map(response => mapAuthApiResponseToAuthenticationResult(response)), + map(({ data }) => mapAuthApiResponseToAuthenticationResult(data)), tap(authenticationResult => { this._setSession(authenticationResult); }) diff --git a/apps/dafa-web/src/app/shared/services/api/authorizations.service.ts b/apps/dafa-web/src/app/shared/services/api/authorizations.service.ts index eb46f3b..0f617ae 100644 --- a/apps/dafa-web/src/app/shared/services/api/authorizations.service.ts +++ b/apps/dafa-web/src/app/shared/services/api/authorizations.service.ts @@ -18,9 +18,7 @@ export class AuthorizationService { private _authorizationsApiUrl = `${environment.api.url}/authorizations`; public authorizations$: Observable = this.httpClient .get(this._authorizationsApiUrl, API_HEADERS) - .pipe( - map(response => response.data.map(authorization => mapAuthorizationApiResponseToAuthorization(authorization))) - ); + .pipe(map(({ data }) => data.map(authorization => mapAuthorizationApiResponseToAuthorization(authorization)))); constructor(private httpClient: HttpClient) {} } diff --git a/apps/dafa-web/src/app/shared/services/api/avrop-api.service.ts b/apps/dafa-web/src/app/shared/services/api/avrop-api.service.ts index e56b5c2..57c919a 100644 --- a/apps/dafa-web/src/app/shared/services/api/avrop-api.service.ts +++ b/apps/dafa-web/src/app/shared/services/api/avrop-api.service.ts @@ -29,7 +29,7 @@ const tempMockDelay = 300; export class AvropApiService { private _apiBaseUrl = `${environment.api.url}/avrop`; - constructor(private httpClient: HttpClient) { } + constructor(private httpClient: HttpClient) {} getNyaAvrop$( tjanstIds: MultiselectFilterOption[], @@ -41,10 +41,8 @@ export class AvropApiService { return this.httpClient .get<{ data: AvropResponse[] }>(`${this._apiBaseUrl}`, { ...API_HEADERS }) .pipe( - filter(response => !!response), - map(response => { - return response.data.map(avrop => mapAvropResponseToAvrop(avrop)) - }) + filter(response => !!response?.data), + map(({ data }) => data.map(avrop => mapAvropResponseToAvrop(avrop))) ); } @@ -58,29 +56,24 @@ export class AvropApiService { selectedKommuner: MultiselectFilterOption[], selectedUtforandeVerksamheter: MultiselectFilterOption[] ): Observable { - return this.httpClient.get<{ data: TjanstResponse[] }>(`${this._apiBaseUrl}/tjanster`) - .pipe( - filter(response => !!response), - map(response => { - return response.data.map(tjanster => { - return { label: mapTjanstResponseToTjanst(tjanster).name } - }) - }) - ); + return this.httpClient.get<{ data: TjanstResponse[] }>(`${this._apiBaseUrl}/tjanster`).pipe( + filter(response => !!response?.data), + map(({ data }) => data.map(tjanster => ({ label: mapTjanstResponseToTjanst(tjanster).name }))) + ); } getSelectableUtforandeVerksamheter$( selectedTjanster: MultiselectFilterOption[], selectedKommuner: MultiselectFilterOption[] ): Observable { - return this.httpClient.get<{ data: UtforandeVerksamhetResponse[] }>(`${this._apiBaseUrl}/utforandeverksamheter`, { ...API_HEADERS }) + return this.httpClient + .get<{ data: UtforandeVerksamhetResponse[] }>(`${this._apiBaseUrl}/utforandeverksamheter`, { ...API_HEADERS }) .pipe( - filter(response => !!response), - map(response => { - return response.data.map(utforandeverksamheter => { - return { label: mapUtforandeVerksamhetResponseToUtforandeVerksamhet(utforandeverksamheter).name } - }) - } + filter(response => !!response?.data), + map(({ data }) => + data.map(utforandeverksamheter => ({ + label: mapUtforandeVerksamhetResponseToUtforandeVerksamhet(utforandeverksamheter).name, + })) ) ); } @@ -89,14 +82,11 @@ export class AvropApiService { selectedTjanster: MultiselectFilterOption[], selectedUtforandeVerksamheter: MultiselectFilterOption[] ): Observable { - return this.httpClient.get<{ data: KommunResponse[] }>(`${this._apiBaseUrl}/kommuner`, { ...API_HEADERS }) + return this.httpClient + .get<{ data: KommunResponse[] }>(`${this._apiBaseUrl}/kommuner`, { ...API_HEADERS }) .pipe( - filter(response => !!response), - map(response => { - return response.data.map(kommun => { - return { label: mapKommunResponseToKommun(kommun).name } - }) - }) + filter(response => !!response?.data), + map(({ data }) => data.map(kommun => ({ label: mapKommunResponseToKommun(kommun).name }))) ); } diff --git a/apps/dafa-web/src/app/shared/services/api/deltagare.service.ts b/apps/dafa-web/src/app/shared/services/api/deltagare.service.ts index 617ce54..69753c6 100644 --- a/apps/dafa-web/src/app/shared/services/api/deltagare.service.ts +++ b/apps/dafa-web/src/app/shared/services/api/deltagare.service.ts @@ -31,8 +31,7 @@ const API_HEADERS = { headers: environment.api.headers }; providedIn: 'root', }) export class DeltagareService extends UnsubscribeDirective { - private _apiBaseUrl = `${environment.api.url}/customerinfo`; - private _apiAvropUrl = `${environment.api.url}/avrop`; + private _apiBaseUrl = `${environment.api.url}/deltagare`; private _currentDeltagareId$ = new BehaviorSubject(null); constructor(private httpClient: HttpClient, private errorService: ErrorService) { @@ -53,8 +52,8 @@ export class DeltagareService extends UnsubscribeDirective { public deltagare$: Observable = this._deltagare$.asObservable(); public allDeltagare$: Observable = this.httpClient - .get<{ data: AvropResponse[] }>(`${this._apiAvropUrl}`, { ...API_HEADERS }) - .pipe(map(response => response.data.map(deltagare => mapResponseToDeltagareCompact(deltagare)))); + .get<{ data: AvropResponse[] }>(`${this._apiBaseUrl}`, { ...API_HEADERS }) + .pipe(map(({ data }) => data.map(deltagare => mapResponseToDeltagareCompact(deltagare)))); public setCurrentDeltagareId(currentDeltagareId: string): void { this._deltagare$.next(null); @@ -63,9 +62,9 @@ export class DeltagareService extends UnsubscribeDirective { private _fetchContactInformation$(id: string): Observable> { return this.httpClient - .get<{ data: ContactInformationResponse }>(`${this._apiBaseUrl}/contact/${id}`, { ...API_HEADERS }) + .get<{ data: ContactInformationResponse }>(`${this._apiBaseUrl}/${id}/contact`, { ...API_HEADERS }) .pipe( - map(response => mapResponseToContactInformation(response.data)), + map(({ data }) => mapResponseToContactInformation(data)), catchError(error => { this.errorService.add(errorToCustomError(error)); return of({}); @@ -75,9 +74,9 @@ export class DeltagareService extends UnsubscribeDirective { private _fetchDriversLicense$(id: string): Observable> { return this.httpClient - .get<{ data: DriversLicenseResponse }>(`${this._apiBaseUrl}/driverlicense/${id}`, { ...API_HEADERS }) + .get<{ data: DriversLicenseResponse }>(`${this._apiBaseUrl}/${id}/driverlicense`, { ...API_HEADERS }) .pipe( - map(response => mapResponseToDriversLicense(response.data)), + map(({ data }) => mapResponseToDriversLicense(data)), catchError(error => { this.errorService.add(errorToCustomError(error)); return of({}); @@ -87,9 +86,9 @@ export class DeltagareService extends UnsubscribeDirective { private _fetchHighestEducation$(id: string): Observable> { return this.httpClient - .get<{ data: HighestEducationResponse }>(`${this._apiBaseUrl}/education/highest/${id}`, { ...API_HEADERS }) + .get<{ data: HighestEducationResponse }>(`${this._apiBaseUrl}/${id}/educationlevels/highest`, { ...API_HEADERS }) .pipe( - map(response => mapResponseToHighestEducation(response.data)), + map(({ data }) => mapResponseToHighestEducation(data)), catchError(error => { this.errorService.add(errorToCustomError(error)); return of({}); @@ -99,31 +98,28 @@ export class DeltagareService extends UnsubscribeDirective { private _fetchEducations$(id: string): Observable { return this.httpClient - .get<{ data: EducationsResponse }>(`${this._apiBaseUrl}/education/${id}`, { ...API_HEADERS }) + .get<{ data: EducationsResponse }>(`${this._apiBaseUrl}/${id}/educations`, { ...API_HEADERS }) .pipe( - map(response => { - if (response.data.utbildningar) { - return response.data.utbildningar.sort((a, b) => - sortFromToDates({ from: a.period_from, to: a.period_tom }, { from: b.period_from, to: b.period_tom }) - ); - } - return []; - }), - map( - educations => educations.map(utbildning => mapResponseToEducation(utbildning)), - catchError(error => { - this.errorService.add(errorToCustomError(error)); - return of([]); - }) - ) + map(({ data }) => + data.utbildningar + ? data.utbildningar.sort((a, b) => + sortFromToDates({ from: a.period_from, to: a.period_tom }, { from: b.period_from, to: b.period_tom }) + ) + : [] + ), + map(educations => educations.map(utbildning => mapResponseToEducation(utbildning))), + catchError(error => { + this.errorService.add(errorToCustomError(error)); + return of([]); + }) ); } private _fetchTranslator$(id: string): Observable { return this.httpClient - .get<{ data: TranslatorResponse }>(`${this._apiBaseUrl}/translator/${id}`, { ...API_HEADERS }) + .get<{ data: TranslatorResponse }>(`${this._apiBaseUrl}/${id}/translator`, { ...API_HEADERS }) .pipe( - map(response => (response.data.sprak ? response.data.sprak.beskrivning : null)), + map(({ data }) => data.sprak?.beskrivning || null), catchError(error => { this.errorService.add(errorToCustomError(error)); return of(''); @@ -133,9 +129,9 @@ export class DeltagareService extends UnsubscribeDirective { private _fetchWorkLanguages$(id: string): Observable { return this.httpClient - .get<{ data: WorkLanguagesResponse }>(`${this._apiBaseUrl}/work/languages/${id}`, { ...API_HEADERS }) + .get<{ data: WorkLanguagesResponse }>(`${this._apiBaseUrl}/${id}/work/languages`, { ...API_HEADERS }) .pipe( - map(response => (response.data.sprak ? response.data.sprak.map(sprak => sprak.beskrivning) : [])), + map(({ data }) => data?.sprak?.map(sprak => sprak.beskrivning) || []), catchError(error => { this.errorService.add(errorToCustomError(error)); return of([]); @@ -145,13 +141,9 @@ export class DeltagareService extends UnsubscribeDirective { private _fetchDisabilities$(id: string): Observable { return this.httpClient - .get<{ data: DisabilityResponse[] }>(`${this._apiBaseUrl}/work/disability/${id}`, { ...API_HEADERS }) + .get<{ data: DisabilityResponse[] }>(`${this._apiBaseUrl}/${id}/work/disabilities`, { ...API_HEADERS }) .pipe( - map(response => - response.data.length - ? response.data.map(funktionsnedsattning => mapResponseToDisability(funktionsnedsattning)) - : [] - ), + map(({ data }) => data?.map(funktionsnedsattning => mapResponseToDisability(funktionsnedsattning)) || []), catchError(error => { this.errorService.add(errorToCustomError(error)); return of([]); @@ -161,16 +153,14 @@ export class DeltagareService extends UnsubscribeDirective { private _fetchWorkExperiences$(id: string): Observable { return this.httpClient - .get<{ data: WorkExperiencesResponse }>(`${this._apiBaseUrl}/work/experience/${id}`, { ...API_HEADERS }) + .get<{ data: WorkExperiencesResponse }>(`${this._apiBaseUrl}/${id}/work/experiences`, { ...API_HEADERS }) .pipe( - map(response => { - if (response.data.arbetslivserfarenheter) { - return response.data.arbetslivserfarenheter.sort((a, b) => + map( + ({ data }) => + data?.arbetslivserfarenheter?.sort((a, b) => sortFromToDates({ from: a.period_from, to: a.period_tom }, { from: b.period_from, to: b.period_tom }) - ); - } - return []; - }), + ) || [] + ), map(workExperiences => workExperiences.map(erfarenhet => mapResponseToWorkExperience(erfarenhet))), catchError(error => { this.errorService.add(errorToCustomError(error)); @@ -181,9 +171,9 @@ export class DeltagareService extends UnsubscribeDirective { private _fetchAvropInformation$(id: string): Observable> { return this.httpClient - .get<{ data: AvropResponse }>(`${this._apiAvropUrl}/${id}`, { ...API_HEADERS }) + .get<{ data: AvropResponse }>(`${this._apiBaseUrl}/${id}/avrop`, { ...API_HEADERS }) .pipe( - map(response => (response.data ? mapAvropResponseToAvrop(response.data) : {})), + map(({ data }) => (data ? mapAvropResponseToAvrop(data) : {})), catchError(error => { this.errorService.add(errorToCustomError(error)); return of({}); diff --git a/apps/dafa-web/src/app/shared/services/api/user.service.ts b/apps/dafa-web/src/app/shared/services/api/user.service.ts index f4d2bd9..e4343ec 100644 --- a/apps/dafa-web/src/app/shared/services/api/user.service.ts +++ b/apps/dafa-web/src/app/shared/services/api/user.service.ts @@ -1,8 +1,13 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { UnsubscribeDirective } from '@dafa-directives/unsubscribe.directive'; import { environment } from '@dafa-environment'; -import { mapUserApiResponseToUser, User, UserApiResponse } from '@dafa-models/user.model'; -import { Observable } from 'rxjs'; +import { OrganizationResponse } from '@dafa-models/api/organization.response.model'; +import { UserInfoResponse } from '@dafa-models/api/user-info.response.model'; +import { mapResponseToOrganization, Organization } from '@dafa-models/organization.model'; +import { mapResponseToUserInfo, UserInfo } from '@dafa-models/user-info.model'; +import { User } from '@dafa-models/user.model'; +import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { filter, map } from 'rxjs/operators'; const API_HEADERS = { headers: environment.api.headers }; @@ -10,12 +15,32 @@ const API_HEADERS = { headers: environment.api.headers }; @Injectable({ providedIn: 'root', }) -export class UserService { - private _userApiUrl = `${environment.api.url}/auth`; - public user$: Observable = this.httpClient.get(this._userApiUrl, API_HEADERS).pipe( - filter(response => !!response.data), - map(response => mapUserApiResponseToUser(response.data)) - ); +export class UserService extends UnsubscribeDirective { + private _authApiUrl = `${environment.api.url}/auth`; + private _user$ = new BehaviorSubject(null); - constructor(private httpClient: HttpClient) {} + public user$: Observable = this._user$.asObservable(); + + constructor(private httpClient: HttpClient) { + super(); + this.unsubscribeOnDestroy( + combineLatest([this._fetchUserInfo$(), this._fetchOrganizations$()]).subscribe(([userInfo, organizations]) => { + this._user$.next({ ...userInfo, organizations }); + }) + ); + } + + private _fetchOrganizations$(): Observable { + return this.httpClient.get<{ data: OrganizationResponse[] }>(`${this._authApiUrl}/organizations`, API_HEADERS).pipe( + filter(response => !!response?.data), + map(({ data }) => data.map(organization => mapResponseToOrganization(organization))) + ); + } + + private _fetchUserInfo$(): Observable { + return this.httpClient.get<{ data: UserInfoResponse }>(`${this._authApiUrl}/userinfo`, API_HEADERS).pipe( + filter(response => !!response?.data), + map(({ data }) => mapResponseToUserInfo(data)) + ); + } } diff --git a/apps/dafa-web/src/environments/environment.api.ts b/apps/dafa-web/src/environments/environment.api.ts index 84b9697..bd90a88 100644 --- a/apps/dafa-web/src/environments/environment.api.ts +++ b/apps/dafa-web/src/environments/environment.api.ts @@ -1,10 +1,14 @@ -export const environment = { +import { Environment } from '@dafa-models/environment.model'; + +export const environment: Environment = { environment: 'api', clientId: '5d08c2e4-763e-42f6-b858-24e4773bb83d', loginUrl: 'https://ciam-test.arbetsformedlingen.se:8443/uas/oauth2/authorization?response_type=code&scope=openid', production: false, api: { url: '/api', - headers: {}, + headers: { + orgnr: '5568301337', // Until we have an organisation-selector + }, }, }; diff --git a/apps/dafa-web/src/environments/environment.prod.ts b/apps/dafa-web/src/environments/environment.prod.ts index 95555c0..f49ee9d 100644 --- a/apps/dafa-web/src/environments/environment.prod.ts +++ b/apps/dafa-web/src/environments/environment.prod.ts @@ -1,4 +1,8 @@ -export const environment: any = { +import { Environment } from '@dafa-models/environment.model'; + +export const environment: Environment = { + environment: 'prod', + clientId: '', loginUrl: 'https://ciam.arbetsformedlingen.se/', production: true, api: { diff --git a/apps/dafa-web/src/environments/environment.ts b/apps/dafa-web/src/environments/environment.ts index 5676262..678702e 100644 --- a/apps/dafa-web/src/environments/environment.ts +++ b/apps/dafa-web/src/environments/environment.ts @@ -1,4 +1,6 @@ -export const environment: any = { +import { Environment } from '@dafa-models/environment.model'; + +export const environment: Environment = { environment: 'local', clientId: '', loginUrl: '/mock-login', diff --git a/config/proxy.conf.api.json b/config/proxy.conf.api.json index a426df3..19a0e90 100644 --- a/config/proxy.conf.api.json +++ b/config/proxy.conf.api.json @@ -1,6 +1,6 @@ { "/api": { - "target": "https://mina-sidor-fa-test-api.tocp.arbetsformedlingen.se", + "target": "https://mina-sidor-fa-test.tocp.arbetsformedlingen.se", "secure": false, "changeOrigin": true } diff --git a/mock-api/dafa-web/scripts/current-user.js b/mock-api/dafa-web/scripts/current-user.js index f85f3ac..f1f2d2c 100644 --- a/mock-api/dafa-web/scripts/current-user.js +++ b/mock-api/dafa-web/scripts/current-user.js @@ -12,11 +12,8 @@ function generateCurrentUser() { id: faker.datatype.uuid(), firstName: faker.name.firstName(), lastName: faker.name.lastName(), - ssn: `${faker.date.between('1950', '2000').toISOString().split('T')[0].replace(/-/g, '')}-${faker.datatype.number({ - min: 1000, - max: 9999, - })}`, - organizations: [ORGANIZATIONS[Math.floor(Math.random() * ORGANIZATIONS.length)]], + roles: ['Admin'], + organizations: chooseRandom(ORGANIZATIONS, ORGANIZATIONS.length), authorizations: chooseRandom(AUTHORIZATIONS, faker.datatype.number(3)), }; } diff --git a/mock-api/dafa-web/scripts/organizations.js b/mock-api/dafa-web/scripts/organizations.js index b21d56e..3ee5403 100644 --- a/mock-api/dafa-web/scripts/organizations.js +++ b/mock-api/dafa-web/scripts/organizations.js @@ -11,13 +11,13 @@ function generateOrganizations(amount = 10) { for (let i = 1; i <= amount; ++i) { organizations.push({ id: faker.datatype.uuid(), - organizationNumber: `${faker.datatype.number({ - min: 100000, - max: 999999 - })}-${faker.datatype.number({ - min: 1000, - max: 9999 - })}`, + organizationNumber: `${faker.datatype.number({ + min: 100000, + max: 999999, + })}${faker.datatype.number({ + min: 1000, + max: 9999, + })}`, name: faker.company.companyName(), kaNumber: faker.datatype.number({ min: 100000, max: 999999 }), address: { diff --git a/mock-api/dafa-web/server.js b/mock-api/dafa-web/server.js index 1acb13f..c37ea65 100644 --- a/mock-api/dafa-web/server.js +++ b/mock-api/dafa-web/server.js @@ -16,13 +16,14 @@ server.use( '/employee*': '/employees$1', '/participants': '/participants?_embed=employees', '/participant/:id': '/participants/:id?_embed=employees', - '/auth': '/currentUser', - '/customerinfo/*/*': '/deltagare/$2', - '/customerinfo': '/deltagare', + '/auth/userinfo': '/currentUser', + '/auth/organizations': '/currentUser', '/avrop/tjanster*': '/tjanster$1', '/avrop/utforandeverksamheter*': '/organizations$1', '/avrop/kommuner*': '/kommuner$1', - '/avrop/:sokandeId': '/avrop?sokandeId=:sokandeId', + '/deltagare': '/avrop', + '/deltagare/:sokandeId/avrop': '/avrop?sokandeId=:sokandeId', + '/deltagare/:sokandeId/*': '/deltagare/:sokandeId', '*page=*': '$1_page=$2', '*limit=*': '$1_limit=$2', '*sort=*': '$1_sort=$2', @@ -53,41 +54,50 @@ router.render = (req, res) => { req.body.createdAt = Date.now(); } - if (pathname.includes('/auth/token')) { - res.jsonp(res.locals.data); - } else { - let data = res.locals.data; - const deltagareRegex = /(?:\/customerinfo\/)(contact|driverlicense|education\/highest|education|translator|work\/disability|work\/languages|work\/experience)/g; - const isDeltagarePath = deltagareRegex.exec(pathname); - const avropRegex = /(?:\/avrop\/)(tjanster|utforandeverksamheter|kommuner|\d)/g; - const isAvropPath = avropRegex.exec(pathname); + let data = res.locals.data; + const deltagareRegex = /(?:\/deltagare\/)(?:\d\/)(contact|driverlicense|educationlevels\/highest|educations|translator|work\/disabilities|work\/languages|work\/experiences)/g; + const isDeltagarePath = deltagareRegex.exec(pathname); + const avropRegex = /(?:\/avrop\/(?:tjanster|utforandeverksamheter|kommuner|\d))|(?:\/deltagare\/\d\/(avrop))/g; + const isAvropPath = avropRegex.exec(pathname); + const authRegex = /(?:\/auth\/)(userinfo|organizations)/g; + const isAuthPath = authRegex.exec(pathname); - if (isDeltagarePath) { - const deltagareSubPath = getDeltagareSubPath(isDeltagarePath[1]); - data = res.locals.data[deltagareSubPath] || {}; + if (isAuthPath) { + const authSubPath = isAuthPath[1]; + + if (authSubPath === 'organizations') { + data = res.locals.data[authSubPath].map(organization => ({ + name: organization.name, + organizationnumber: organization.organizationNumber, + })); } - if (isAvropPath) { - if (params) { - const newData = []; - params.forEach((value, key) => { - if (key === 'kommunCodes') { - value = +value; - } - - newData.push(...data.filter(item => item[`related_${key}`].includes(value))); - }); - - data = newData.filter((value, index, arr) => arr.findIndex(item => item.code === value.code) === index); - } else if (isAvropPath[1]) { - data = data[0]; - } - } - - res.jsonp({ - data, - ...appendMetaData(params, res), - }); } + + if (isDeltagarePath) { + const deltagareSubPath = getDeltagareSubPath(isDeltagarePath[1]); + data = res.locals.data[deltagareSubPath] || {}; + } + if (isAvropPath) { + if (params) { + const newData = []; + params.forEach((value, key) => { + if (key === 'kommunCodes') { + value = +value; + } + + newData.push(...data.filter(item => item[`related_${key}`].includes(value))); + }); + + data = newData.filter((value, index, arr) => arr.findIndex(item => item.code === value.code) === index); + } else if (isAvropPath[1]) { + data = data[0]; + } + } + + res.jsonp({ + data, + ...appendMetaData(params, res), + }); }; server.use(router); @@ -116,13 +126,13 @@ function appendMetaData(params, res) { function getDeltagareSubPath(path) { switch (path) { - case 'education/highest': + case 'educationlevels/highest': return 'highestEducation'; - case 'work/disability': + case 'work/disabilities': return 'disabilities'; case 'work/languages': return 'workLanguages'; - case 'work/experience': + case 'work/experiences': return 'workExperiences'; default: return path;