feat(employee): Matched models to the API and adjusted mock-api. (TV-346)

Squashed commit of the following:

commit 0f10a7864960cae47694212042f9d58053b05a0c
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date:   Wed Aug 18 14:13:15 2021 +0200

    Changed tjanst and utforandeVerksamhet to plural

commit 3ffe861d8721692d0b49b0f333f2f52186b23560
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date:   Wed Aug 18 12:26:43 2021 +0200

    Updated fetching single employee in mock-api

commit ae101885a90367b86b77faadaa171816aa2ffcaa
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date:   Wed Aug 18 12:23:28 2021 +0200

    Changed models for employees and fixed mock-api
This commit is contained in:
Erik Tiekstra
2021-08-18 14:16:17 +02:00
parent b7c7b6b6b0
commit 5bb81c3bd4
9 changed files with 158 additions and 115 deletions
@@ -0,0 +1,25 @@
import { PaginationMeta } from '@msfa-models/pagination-meta.model';
export interface EmployeeCompactResponse {
ciamUserId: string;
name: string;
tjanst: string[];
utforandeVerksamhet: string[];
}
export interface EmployeeResponse {
ciamUserId: string;
firstName: string;
lastName: string;
email: string;
personnummer: string;
roles: string[];
tjansteKoder: string[];
utforandeVerksamhetIds: string[];
adressIds: string[];
}
export interface EmployeesApiResponse {
data: EmployeeCompactResponse[];
meta: PaginationMeta;
}
@@ -1,75 +1,81 @@
import { Authorization } from '@msfa-enums/authorization.enum';
import { Organization } from './organization.model';
import { EmployeeCompactResponse, EmployeeResponse } from './api/employee.response.model';
import { PaginationMeta } from './pagination-meta.model';
import { Service } from './service.model';
export interface EmployeeCompact {
id: string;
fullName: string;
tjanster: string[];
utforandeVerksamheter: string[];
}
export interface Employee {
id: string;
firstName: string;
lastName: string;
fullName?: string;
email: string;
ssn: string;
organizations: Organization[];
services: Service[];
authorizations: Authorization[];
createdAt?: number;
}
export interface EmployeesApiResponse {
data: Employee[];
meta: PaginationMeta;
roles: string[];
tjanstCodes: string[];
utforandeVerksamhetIds: string[];
utforandeAdressIds: string[];
}
export interface EmployeesData {
data: Employee[];
data: EmployeeCompact[];
meta: PaginationMeta;
}
export interface EmployeeApiResponse {
data: Employee;
export interface EmployeeRequestData {
email: string;
roles: string[];
tjansteKoder: string[];
utforandeVerksamhetIds: string[];
adressIds: string[];
}
export interface EmployeeApiResponseData {
id: string;
firstName: string;
lastName: string;
ssn: string;
organizations: Organization[];
authorizations: Authorization[];
services: Service[];
}
export function mapEmployeeToRequestData(data: Employee): EmployeeRequestData {
const { email, roles, tjanstCodes, utforandeVerksamhetIds, utforandeAdressIds } = data;
export interface EmployeeApiRequestData {
firstName: string;
lastName: string;
ssn: string;
organizations: Organization[];
services: Service[];
authorizations: Authorization[];
}
export function mapEmployeeToEmployeeApiRequestData(data: Employee): EmployeeApiRequestData {
const { firstName, lastName, ssn, services, organizations, authorizations } = data;
return {
firstName,
lastName,
ssn,
services,
organizations,
authorizations,
email,
roles,
tjansteKoder: tjanstCodes,
utforandeVerksamhetIds,
adressIds: utforandeAdressIds,
};
}
export function mapEmployeeReponseToEmployee(data: EmployeeApiResponseData): Employee {
const { id, firstName, lastName, ssn, services, organizations, authorizations } = data;
export function mapResponseToEmployeeCompact(data: EmployeeCompactResponse): EmployeeCompact {
const { ciamUserId, name, tjanst, utforandeVerksamhet } = data;
return {
id,
firstName,
lastName,
fullName: `${firstName} ${lastName}`,
organizations,
authorizations,
services,
ssn,
id: ciamUserId,
fullName: name,
tjanster: tjanst || [],
utforandeVerksamheter: utforandeVerksamhet || [],
};
}
export function mapResponseToEmployee(data: EmployeeResponse): Employee {
const {
ciamUserId,
firstName,
lastName,
email,
personnummer,
roles,
tjansteKoder,
utforandeVerksamhetIds,
adressIds,
} = data;
return {
id: ciamUserId,
firstName,
lastName,
email,
ssn: personnummer,
roles,
tjanstCodes: tjansteKoder,
utforandeVerksamhetIds,
utforandeAdressIds: adressIds,
};
}