-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
148 lines (136 loc) · 3.66 KB
/
index.ts
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { AxiosError } from "axios";
import { endOfWeek, format, startOfWeek } from "date-fns";
import inquirer from "inquirer";
import { generateDailyCompletionReport } from "./scripts/daily-completion-report";
import { generateDailyJobPlanReport } from "./scripts/daily-job-plan-report";
import { generateMonthlyReport } from "./scripts/monthly-report";
import { generateWeeklyReport } from "./scripts/weekly-report";
try {
const { reportType } = await inquirer.prompt([
{
type: "select",
name: "reportType",
message: "Select the type of report you want to generate",
choices: [
"Daily Completion Report",
"Daily Job Plan",
"Monthly Report",
"Weekly Report",
] as const,
},
]);
if (reportType === "Daily Completion Report") {
const { date, month, year } = await inquirer.prompt([
{
type: "number",
name: "date",
message: "Enter the date (1-31):",
step: 1,
min: 1,
max: 31,
default: new Date().getDate(),
},
{
type: "number",
name: "month",
message: "Enter the month (1-12):",
step: 1,
min: 1,
max: 12,
default: new Date().getMonth() + 1,
},
{
type: "number",
name: "year",
message: "Enter the year (YYYY):",
step: 1,
min: 1900,
max: 2100,
default: new Date().getFullYear(),
},
]);
await generateDailyCompletionReport(year, month, date);
}
if (reportType === "Daily Job Plan") {
const { date, month, year } = await inquirer.prompt([
{
type: "number",
name: "date",
message: "Enter the date (1-31):",
step: 1,
min: 1,
max: 31,
default: new Date().getDate(),
},
{
type: "number",
name: "month",
message: "Enter the month (1-12):",
step: 1,
min: 1,
max: 12,
default: new Date().getMonth() + 1,
},
{
type: "number",
name: "year",
message: "Enter the year (YYYY):",
step: 1,
min: 1900,
max: 2100,
default: new Date().getFullYear(),
},
]);
await generateDailyJobPlanReport(year, month, date);
}
if (reportType === "Monthly Report") {
const { month, year } = await inquirer.prompt([
{
type: "number",
name: "month",
message: "Enter the month (1-12):",
step: 1,
min: 1,
max: 12,
default: new Date().getMonth() + 1,
},
{
type: "number",
name: "year",
message: "Enter the year (YYYY):",
step: 1,
min: 1900,
max: 2100,
default: new Date().getFullYear(),
},
]);
await generateMonthlyReport(year, month);
}
if (reportType === "Weekly Report") {
const { startDate, endDate } = await inquirer.prompt([
{
type: "input",
name: "startDate",
message: "Enter the start date (YYYY-MM-DD):",
default: format(startOfWeek(new Date()), "yyyy-MM-dd"),
},
{
type: "input",
name: "endDate",
message: "Enter the end date (YYYY-MM-DD):",
default: format(endOfWeek(new Date()), "yyyy-MM-dd"),
},
]);
await generateWeeklyReport(startOfWeek(startDate), endOfWeek(endDate));
}
console.log("✅ Report generated successfully!");
} catch (error) {
if (error instanceof AxiosError) {
console.error(
`❌ The server returned an error:\n${error.response?.data["error"]["message"]}`
);
process.exit(1);
}
console.error(`❌ An unknown error occurred: ${error}`);
process.exit(1);
}