Squashed commit of the following: commit 4fd71e0d0655a0d75dda59151ac74e2361f187bc Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Aug 20 10:59:46 2021 +0200 Updated RoleEnum and mock-data för roles commit f05a93239727ce1245650ece3b48cf75dc7091ca Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Aug 20 08:34:20 2021 +0200 Fixed issue with mock-api commit c31e94da6b90e442fd84c5113789db245be81c6d Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Aug 20 08:26:14 2021 +0200 Fixed issue with tjanster commit a183a08f0446cdaea7d01c8935d88ac436b0438f Merge: eb310c11e2d925Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Aug 20 07:59:06 2021 +0200 Merge branch 'develop' into feature/TV-341-erik commit eb310c10bdf0f4b60032bdda97df75c19bdbf447 Merge: 877b68bfae7d9aAuthor: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Aug 20 07:21:39 2021 +0200 Merged develop and fixed conflicts commit 877b68b8827e89cfd230856c9d8247f1cd8db264 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Thu Aug 19 15:01:55 2021 +0200 Now fetching tjanster from mock-api commit 1ecd26595b21ea46ce6fb0c193c6642f66250ae3 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Thu Aug 19 14:24:11 2021 +0200 Some more changes to employee-card commit e42ae254e7aa7b994627fdccb7037493b116d6a2 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Thu Aug 19 13:44:23 2021 +0200 Added new enum Role and fixed some issues mapping roles inside employee-card commit 7801831d83feae5ef5e5b92e6421b18863b2a1db Merge: c78f3f8d6e4666Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Thu Aug 19 12:37:56 2021 +0200 Merge branch 'develop' into feature/TV-341-fe-anpassa-personal-kortet-sa-att-den-ar-enligt-skiss commit c78f3f886752477d2dbc4af20356252af4128440 Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Thu Aug 19 11:19:56 2021 +0200 Authorization commit 9c043720a9cfa5fd6943013f643d948a50c8f135 Merge: 77d6a9cffeb372Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Thu Aug 19 11:19:43 2021 +0200 Merge branch 'develop' into feature/TV-341-fe-anpassa-personal-kortet-sa-att-den-ar-enligt-skiss # Conflicts: # apps/mina-sidor-fa/src/app/pages/administration/pages/employee-card/employee-card.component.scss # apps/mina-sidor-fa/src/app/pages/administration/pages/employee-card/employee-card.module.ts # apps/mina-sidor-fa/src/app/shared/enums/employee-authorization.enum.ts commit 77d6a9c600e6b42e97fa5431ed37ad430c5febd3 Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Wed Aug 18 10:22:45 2021 +0200 Moved subscription, added icons, refactured markup commit b43c18e28b5aabb8115fa659a98b4ae8c0a7bf40 Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Tue Aug 17 10:50:02 2021 +0200 unsubscribed commit 9f48cddc75872fc3f740c53de998cd54666b0b1d Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Mon Aug 16 16:40:08 2021 +0200 Unsubscription behöver läggas till efter genomgång av hur unsubscribeOnDestroy fungerar commit b2cef346f18482e72c11c09d0a6e629370d01bd5 Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Mon Aug 16 16:37:13 2021 +0200 Authorization commit 5fe0b5d5fc725551f9e794cbaa70dc0f077f8717 Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Fri Aug 13 15:46:50 2021 +0200 - Changed first h2 to h3 - Changed link to routerLink commit fd1cb3c6249535ce84e61df035cae63352b1b00b Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Fri Aug 13 11:53:36 2021 +0200 Amends after PR commit 13e9881e3680bd829736205b3fef57b2228638d5 Author: WP\holno <nikola.holst-nikolic@arbetsformedlingen.se> Date: Wed Aug 11 16:19:36 2021 +0200 Employee-card amends to look more like the sketch.
162 lines
4.9 KiB
JavaScript
162 lines
4.9 KiB
JavaScript
import jsonServer from 'json-server';
|
|
|
|
const server = jsonServer.create();
|
|
const router = jsonServer.router('api.json');
|
|
const middlewares = jsonServer.defaults();
|
|
|
|
server.use(middlewares);
|
|
|
|
server.use(
|
|
jsonServer.rewriter({
|
|
'/api/*': '/$1',
|
|
'*sort=utforandeVerksamhet*': '$1sort=utforandeVerksamhet[0]$2',
|
|
'*sort=tjanst*': '$1sort=tjanst[0]$2',
|
|
'/users/:id': '/employees?ciamUserId=:id',
|
|
'/users*': '/employees$1',
|
|
'/employees*search=*': '/employees$1fullName_like=$2',
|
|
'/employees*onlyEmployeesWithoutAuthorization=*': '/employees$1roles.length_lte=1',
|
|
'/employees/invite': '/invites',
|
|
'/employees*': '/employees$1',
|
|
'/services*': '/tjanster$1',
|
|
'/participants': '/participants?_embed=employees',
|
|
'/participant/:id': '/participants/:id?_embed=employees',
|
|
'/auth/userinfo': '/currentUser',
|
|
'/auth/organizations': '/currentUser',
|
|
'/avrop/tjanster*': '/avropTjanster$1',
|
|
'/avrop/utforandeverksamheter*': '/organizations$1',
|
|
'/avrop/kommuner*': '/kommuner$1',
|
|
'/deltagare?*': '/avrop?$1',
|
|
'/deltagare/:sokandeId/avrop': '/avrop?sokandeId=:sokandeId',
|
|
'/deltagare/:sokandeId/*': '/deltagare/:sokandeId',
|
|
'*page=*': '$1_page=$2',
|
|
'*limit=*': '$1_limit=$2',
|
|
'*sort=*': '$1_sort=$2',
|
|
'*order=*': '$1_order=$2',
|
|
'/auth/token?accessCode=auth_code_from_CIAM_with_all_permissions': '/getTokenFullAccess',
|
|
})
|
|
);
|
|
|
|
router.render = (req, res) => {
|
|
const method = req.originalMethod;
|
|
const parsedUrl = method === 'GET' ? req._parsedOriginalUrl : req._parsedUrl;
|
|
const pathname = parsedUrl.pathname;
|
|
const params = parsedUrl.query ? new URLSearchParams(parsedUrl.query) : null;
|
|
const requestHeaders = req.headers;
|
|
|
|
// all paths except /auth/token requires Authorization header.
|
|
if (!pathname.includes('/auth/token') && !requestHeaders.authorization) {
|
|
return res.status(401).jsonp({ error: 'No valid access-token' });
|
|
}
|
|
|
|
// Return custom error when status is 404.
|
|
if (res.statusCode === 404) {
|
|
return res.status(404).jsonp({ error: `Can't find path: ${pathname}` });
|
|
}
|
|
|
|
// Add createdAt to the body
|
|
if (method === 'POST') {
|
|
req.body.createdAt = Date.now();
|
|
}
|
|
|
|
let data = res.locals.data;
|
|
const employeeRegex = /(?:\/users\/)(.*)/;
|
|
const isEmployeePath = employeeRegex.exec(pathname);
|
|
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 (isEmployeePath) {
|
|
data = data[0];
|
|
}
|
|
|
|
if (isAuthPath) {
|
|
const authSubPath = isAuthPath[1];
|
|
|
|
if (authSubPath === 'organizations') {
|
|
data = res.locals.data[authSubPath].map(organization => ({
|
|
name: organization.name,
|
|
organizationnumber: organization.organizationNumber,
|
|
}));
|
|
}
|
|
}
|
|
|
|
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];
|
|
}
|
|
}
|
|
|
|
if (pathname === '/deltagare') {
|
|
data = data.map(({ sokandeId, fornamn, efternamn, tjansteNamn, utforandeverksamhet, adress }) => ({
|
|
sokandeId: sokandeId.toString(),
|
|
fornamn,
|
|
efternamn,
|
|
tjanst: tjansteNamn,
|
|
utforandeVerksamhet: utforandeverksamhet,
|
|
utforandeAdress: adress,
|
|
}));
|
|
}
|
|
|
|
res.jsonp({
|
|
data,
|
|
...appendMetaData(params, res),
|
|
});
|
|
};
|
|
|
|
server.use(router);
|
|
server.listen(8000, () => {
|
|
console.info('JSON Server is running');
|
|
});
|
|
|
|
function appendMetaData(params, res) {
|
|
if (params && params.has('page')) {
|
|
const limit = +params.get('limit');
|
|
const page = +params.get('page');
|
|
const count = res.get('X-Total-Count');
|
|
const totalPages = Math.ceil(count / limit);
|
|
return {
|
|
meta: {
|
|
count,
|
|
limit,
|
|
page,
|
|
totalPages,
|
|
},
|
|
};
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function getDeltagareSubPath(path) {
|
|
switch (path) {
|
|
case 'educationlevels/highest':
|
|
return 'highestEducation';
|
|
case 'work/disabilities':
|
|
return 'disabilities';
|
|
case 'work/languages':
|
|
return 'workLanguages';
|
|
case 'work/experiences':
|
|
return 'workExperiences';
|
|
default:
|
|
return path;
|
|
}
|
|
}
|