-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleaves.js
37 lines (34 loc) · 1.42 KB
/
leaves.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const path = require('path');
const faker = require('faker');
const _ = require('lodash');
const fs = require('fs');
const beautify = require("json-beautify");
const { Factory } = require('rosie');
const leaves = [];
Factory.define('leaves')
.sequence('id')
.attr('name', () => { return faker.name.firstName(); })
.attr('startDate', () => {
const start = new Date();
const end = new Date();
end.setDate(start.getDate() + 2);
const date = faker.date.between(
start.getFullYear() + '-' + (start.getMonth() + 1) + '-' + start.getDate(),
end.getFullYear() + '-' + (end.getMonth() + 1) + '-' + end.getDate());
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
})
.attr('endDate', () => {
const start = new Date();
start.setDate(start.getDate() + 3);
const end = new Date();
end.setDate(start.getDate() + 4);
const date = faker.date.between(
start.getFullYear() + '-' + (start.getMonth() + 1) + '-' + start.getDate(),
end.getFullYear() + '-' + (end.getMonth() + 1) + '-' + end.getDate());
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
});
_.times(50, () => {
const leave = Factory.build('leaves');
leaves.push(leave);
});
fs.writeFileSync(path.join(__dirname, '../data/leaves.json'), beautify({ leaves }, null, 2, 80), 'utf8');