-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
53 lines (51 loc) · 1.51 KB
/
sample.js
File metadata and controls
53 lines (51 loc) · 1.51 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
let dotenv = require('dotenv');
dotenv.config();
let fs = require('fs-extra'),
api = require('./src/api'),
logger = require('./src/util').logger,
inquirer = require('inquirer'),
prompts = require('./src/prompts'),
moment = require('moment'),
zeroPad = require('./src/util').zeroPad,
changeCase = require('change-case'),
user = null;
inquirer.prompt(prompts.config)
.then(
answers => {
if (!answers.sessionToken || !answers.firmId || !answers.staffId) {
logger.error('Missing session token, firm ID, or staff ID.');
process.exit();
}
process.env.BIGTIME_SESSION_TOKEN = answers.sessionToken;
process.env.BIGTIME_FIRM_ID = answers.firmId;
process.env.BIGTIME_STAFF_ID = answers.staffId;
return api.staff.detail({staffId: process.env.BIGTIME_STAFF_ID});
}
)
.then(
response => {
user = response.body;
return inquirer.prompt(prompts.sample.dateRange);
},
() => {
// TODO
}
)
.then(
answers => {
return api.sample.run(answers);
}
)
.then(
response => {
if (!response) return;
let now = moment(),
month = zeroPad(now.month() + 1),
day = zeroPad(now.date()),
filename = `./results/${changeCase.paramCase(user.FullName)}/sample/${now.year()}-${month}-${day}-${now.valueOf()}.json`;
fs.outputFile(filename, JSON.stringify(response), err => {
if (err) throw err;
logger.info(`Saved results to ${filename}`);
});
}
);