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:
@@ -1,7 +1,7 @@
|
||||
import faker from 'faker';
|
||||
import authorizations from './authorizations.js';
|
||||
import organizations from './organizations.js';
|
||||
import tjanster from './tjanster.js';
|
||||
import chooseRandom from './utils/choose-random.util.js';
|
||||
|
||||
faker.locale = 'sv';
|
||||
|
||||
@@ -12,24 +12,31 @@ function generateEmployees(amount = 10) {
|
||||
const employees = [];
|
||||
|
||||
for (let i = 1; i <= amount; ++i) {
|
||||
const person = {
|
||||
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)]],
|
||||
services: [TJANSTER[Math.floor(Math.random() * TJANSTER.length)]],
|
||||
authorizations: i % 2 === 0 ? authorizations.generate() : [],
|
||||
createdAt: Date.now(),
|
||||
const firstName = faker.name.firstName();
|
||||
const lastName = faker.name.lastName();
|
||||
const currentTjanster = chooseRandom(TJANSTER, faker.datatype.number({ min: 1, max: TJANSTER.length }));
|
||||
const currentOrganizations = chooseRandom(ORGANIZATIONS, faker.datatype.number({ min: 1, max: 5 }));
|
||||
|
||||
const employee = {
|
||||
ciamUserId: faker.datatype.uuid(),
|
||||
firstName,
|
||||
lastName,
|
||||
name: `${firstName} ${lastName}`,
|
||||
personnummer: `${faker.date
|
||||
.between('1950', '2000')
|
||||
.toISOString()
|
||||
.split('T')[0]
|
||||
.replace(/-/g, '')}-${faker.datatype.number({
|
||||
min: 1000,
|
||||
max: 9999,
|
||||
})}`,
|
||||
tjanst: currentTjanster.map(tjanst => tjanst.name),
|
||||
tjansteKoder: currentTjanster.map(tjanst => tjanst.code),
|
||||
utforandeVerksamhet: currentOrganizations.map(organization => organization.name),
|
||||
utforandeVerksamhetIds: currentOrganizations.map(organization => organization.id),
|
||||
};
|
||||
|
||||
person.fullName = `${person.firstName} ${person.lastName}`;
|
||||
employees.push(person);
|
||||
employees.push(employee);
|
||||
}
|
||||
|
||||
console.info('Employees generated...');
|
||||
|
||||
@@ -8,10 +8,10 @@ function generateTjanster() {
|
||||
code: faker.datatype.uuid(),
|
||||
name: 'Kundval Rusta och matcha',
|
||||
},
|
||||
{
|
||||
code: faker.datatype.uuid(),
|
||||
name: 'Karriärvägledning',
|
||||
},
|
||||
// {
|
||||
// code: faker.datatype.uuid(),
|
||||
// name: 'Karriärvägledning',
|
||||
// },
|
||||
// {
|
||||
// code: faker.datatype.uuid(),
|
||||
// name: 'STOM',
|
||||
|
||||
@@ -9,13 +9,15 @@ server.use(middlewares);
|
||||
server.use(
|
||||
jsonServer.rewriter({
|
||||
'/api/*': '/$1',
|
||||
'*sort=services*': '$1sort=services[0].name$2',
|
||||
'*sort=organizations*': '$1sort=organizations[0].address.city$2',
|
||||
'*sort=utforandeVerksamhet*': '$1sort=utforandeverksamhet$2',
|
||||
'*sort=tjanst*': '$1sort=tjansteNamn$2',
|
||||
'/employee*search=*': '/employee$1fullName_like=$2',
|
||||
'/employee*onlyEmployeesWithoutAuthorization=*': '/employee$1authorizations.length_gte=1',
|
||||
'/employee*': '/employees$1',
|
||||
'*sort=fullName*': '$1sort=name$2',
|
||||
'*sort=utforandeVerksamheter*': '$1sort=utforandeVerksamhet[0]$2',
|
||||
'*sort=tjanster*': '$1sort=tjanst[0]$2',
|
||||
'/users/:id': '/employees?ciamUserId=:id',
|
||||
'/users*': '/employees$1',
|
||||
'/employees*search=*': '/employees$1fullName_like=$2',
|
||||
'/employees*onlyEmployeesWithoutAuthorization=*': '/employees$1authorizations.length_gte=1',
|
||||
'/employees/invite': '/invites',
|
||||
'/employees*': '/employees$1',
|
||||
'/participants': '/participants?_embed=employees',
|
||||
'/participant/:id': '/participants/:id?_embed=employees',
|
||||
'/auth/userinfo': '/currentUser',
|
||||
|
||||
Reference in New Issue
Block a user