This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from isnifer/daily-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.js
80 lines (66 loc) · 2.2 KB
/
report.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { writeFileSync } = require('fs')
const clipboardy = require('clipboardy')
const {
PATH_TO_REPORT,
PATH_TO_PROFILE,
NEXT_QUESTION,
TASK_TYPES,
TASK_NUMBER_REGEX,
} = require('./constants')
const { simpleQuestionsReducer, summaryQuestionsReducer } = require('./parsers')
const answers = {}
module.exports = {
updateReport: (response, regularQuestion, refinementQuestion) => {
const [answer] = Object.values(response)
const answersInQuestion = answers[regularQuestion]
answers[regularQuestion] = answersInQuestion || []
if (answer !== NEXT_QUESTION) {
if (refinementQuestion) {
answersInQuestion[answersInQuestion.length - 1][refinementQuestion] = answer
}
if (regularQuestion && !refinementQuestion) {
const TASK_NUMBER = TASK_NUMBER_REGEX.test(answer) ? answer : `[${TASK_TYPES.CUSTOM}]`
const DESCRIPTION = TASK_NUMBER_REGEX.test(answer) ? null : { DESCRIPTION: answer }
answers[regularQuestion].push({
TASK_NUMBER,
...(DESCRIPTION || {}),
})
}
}
return response
},
writeReport: () => {
const today = new Date()
.toLocaleDateString()
.split('/')
.reverse()
.join('/')
// eslint-disable-next-line
const report = require(PATH_TO_REPORT)
const content = {
...report,
[today]: answers,
}
writeFileSync(PATH_TO_REPORT, JSON.stringify(content, null, 2))
const QUESTIONS = Object.entries(answers)
const SIMPLE_QUESTIONS = QUESTIONS.slice(0, 3)
const SUMMARY = QUESTIONS.slice(3)
const summaryLines = SUMMARY.reduce(summaryQuestionsReducer, [])
const summaryReport = summaryLines.length ? ['', 'Summary', ...summaryLines] : []
const todayReport = [].concat(
// eslint-disable-next-line
require(PATH_TO_PROFILE).fullName,
SIMPLE_QUESTIONS.reduce(simpleQuestionsReducer, []),
summaryReport
).join('\n')
// eslint-disable-next-line
console.log([
'Ваш репорт готов:',
'',
todayReport,
'',
'Вставьте репорт из буфера обмена (да-да, он уже там!) в Slack',
].join('\n'))
clipboardy.writeSync(todayReport)
},
}