51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
import faker from 'faker';
|
|
import organizations from './organizations.js';
|
|
import tjanster from './tjanster.js';
|
|
import chooseRandom from './utils/choose-random.util.js';
|
|
|
|
faker.locale = 'sv';
|
|
|
|
const TJANSTER = tjanster.generate();
|
|
const ORGANIZATIONS = organizations.generate();
|
|
|
|
function generateEmployees(amount = 10) {
|
|
const employees = [];
|
|
|
|
for (let i = 1; i <= amount; ++i) {
|
|
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 hasBehorigheter = Math.random() > 0.1;
|
|
|
|
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,
|
|
})}`,
|
|
roles: hasBehorigheter ? ['Admin'] : [],
|
|
tjanst: hasBehorigheter ? currentTjanster.map(tjanst => tjanst.name) : [],
|
|
tjansteKoder: hasBehorigheter ? currentTjanster.map(tjanst => tjanst.code) : [],
|
|
utforandeVerksamhet: hasBehorigheter ? currentOrganizations.map(organization => organization.name) : [],
|
|
utforandeVerksamhetIds: hasBehorigheter ? currentOrganizations.map(organization => organization.id) : [],
|
|
};
|
|
|
|
employees.push(employee);
|
|
}
|
|
|
|
console.info('Employees generated...');
|
|
return employees;
|
|
}
|
|
|
|
export default {
|
|
generate: generateEmployees,
|
|
};
|