Added foundation of a simple mock-api

This commit is contained in:
Erik Tiekstra
2021-03-24 15:25:38 +01:00
committed by Erik Tiekstra
parent 81ac40ef31
commit e1b8979b99
28 changed files with 3807 additions and 33 deletions

View File

@@ -0,0 +1,8 @@
import fs from 'fs';
import participants from './participants.js';
const apiData = {
participants: participants.generate(50),
};
fs.writeFileSync('api.json', JSON.stringify(apiData, null, '\t'));

View File

@@ -0,0 +1,27 @@
import faker from 'faker';
faker.locale = 'sv';
const AVAILABLE_SERVICES = ['KROM', 'STOM', 'KVL'];
function generateParticipants(amount = 10) {
const participants = [];
for (let id = 0; id <= amount; ++id) {
participants.push({
id,
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
service: AVAILABLE_SERVICES[Math.floor(Math.random() * AVAILABLE_SERVICES.length)],
errandNumber: faker.random.number({ min: 100000, max: 999999 }),
startDate: faker.date.recent(),
endDate: faker.date.soon(),
});
}
return participants;
}
export default {
generate: generateParticipants,
};