feat(api): Reflected api-changes to different api-requests and fixed mock-api. (TV-371)
Squashed commit of the following: commit 01ef668c8ddd8e0d8ff459d60f45ca0c7780f184 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Aug 17 11:53:36 2021 +0200 Fixed issue with authentication commit e40f4728203388175f405184693b3604001afc5e Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Aug 17 11:09:46 2021 +0200 Added some more fixes to API requests based on latest changes commit 920eb03302ee65852141f7bcce72d832507d2c07 Merge: c2d5d7cbfa8ed5Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Aug 17 09:34:48 2021 +0200 Merge branch 'develop' into feature/TV-371-api-fix commit c2d5d7c9a7b812a57234b0038da79bc1d0c07881 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Aug 17 07:50:11 2021 +0200 Updated mock-api commit 5578b0ffdba27e0e80dabe05e920b96e46331fb0 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Aug 16 15:17:46 2021 +0200 Fixed fetching of userinfo and organizations commit 116b3092bf9a685354738146ef7cd0eb619fa009 Merge: 6a32f1901dc4b3Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Aug 16 13:09:53 2021 +0200 Merge branch 'develop' into feature/TV-371-api-fix commit 6a32f1997e9ddb912cf2995a333faa9aa0205852 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Aug 16 13:07:38 2021 +0200 Updated API-endpoints
This commit is contained in:
@@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user