Added foundation of a simple mock-api
This commit is contained in:
committed by
Erik Tiekstra
parent
81ac40ef31
commit
e1b8979b99
8
mock-api/dafa-web/scripts/generate-api.js
Normal file
8
mock-api/dafa-web/scripts/generate-api.js
Normal 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'));
|
||||
27
mock-api/dafa-web/scripts/participants.js
Normal file
27
mock-api/dafa-web/scripts/participants.js
Normal 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,
|
||||
};
|
||||
Reference in New Issue
Block a user