@@ -44,27 +44,34 @@ export async function addCategory(category_name) {
44
44
}
45
45
46
46
export function getIncs ( numberOfDaysAgo ) {
47
- if ( numberOfDaysAgo === undefined ) {
48
- const query = {
49
- text : `SELECT * FROM incs` ,
50
- } ;
51
- return client . query ( query ) ;
52
- } else {
53
- // Calculate the date range
54
- const dateAgo = new Date ( ) ;
55
- dateAgo . setDate ( dateAgo . getDate ( ) - numberOfDaysAgo ) ;
56
- const formattedDateAgo = dateAgo . toISOString ( ) ; // ISO8601 format
47
+ try {
48
+ if ( numberOfDaysAgo === undefined ) {
49
+ const query = {
50
+ text : `SELECT * FROM incs` ,
51
+ } ;
52
+ return client . query ( query ) ;
53
+ } else {
54
+ // Calculate the date range
55
+ const dateAgo = new Date ( ) ;
56
+ dateAgo . setDate ( dateAgo . getDate ( ) - numberOfDaysAgo ) ;
57
+ const formattedDateAgo = dateAgo . toISOString ( ) ; // ISO8601 format
57
58
58
- // Construct the SQL query with parameterized query
59
- const query = {
60
- text : `SELECT * FROM incs WHERE created_at >= $1` ,
61
- values : [ formattedDateAgo ] ,
62
- } ;
63
- return client . query ( query ) ;
59
+ // Construct the SQL query with parameterized query
60
+ const query = {
61
+ text : `SELECT * FROM incs WHERE created_at >= $1` ,
62
+ values : [ formattedDateAgo ] ,
63
+ } ;
64
+ return client . query ( query ) ;
65
+ }
66
+ }
67
+ catch ( err ) {
68
+ console . error ( "Error fetching incs" , err
69
+ ) ;
64
70
}
65
71
}
66
72
67
73
export function getIncByCategory ( numberOfDaysAgo ) {
74
+ try {
68
75
if ( numberOfDaysAgo === undefined ) {
69
76
const query = {
70
77
text : `SELECT category, COUNT(*) FROM incs GROUP BY category` ,
@@ -84,37 +91,46 @@ export function getIncByCategory(numberOfDaysAgo) {
84
91
return client . query ( query ) ;
85
92
}
86
93
}
94
+ catch ( err ) {
95
+ console . error ( "Error fetching incs" , err ) ;
96
+ }
97
+ }
87
98
88
99
export async function getIncNumberByWeek ( numberOfDaysAgo ) {
89
- let queryText ;
100
+ try {
101
+ let queryText ;
90
102
91
- if ( numberOfDaysAgo === undefined ) {
92
- queryText = `
93
- SELECT DATE_TRUNC('week', created_at) AS week, COUNT(*) AS count
94
- FROM incs
95
- GROUP BY week
96
- ORDER BY week;
97
- ` ;
98
- } else {
99
- // Calculate the date range
100
- const dateAgo = new Date ( ) ;
101
- dateAgo . setDate ( dateAgo . getDate ( ) - numberOfDaysAgo ) ;
102
- const formattedDateAgo = dateAgo . toISOString ( ) ; // ISO8601 format
103
-
104
- // Construct the SQL query with parameterized query
105
- queryText = {
106
- text : `
103
+ if ( numberOfDaysAgo === undefined ) {
104
+ queryText = `
107
105
SELECT DATE_TRUNC('week', created_at) AS week, COUNT(*) AS count
108
106
FROM incs
109
- WHERE created_at >= $1
110
107
GROUP BY week
111
108
ORDER BY week;
112
- ` ,
113
- values : [ formattedDateAgo ] ,
114
- } ;
115
- }
109
+ ` ;
110
+ } else {
111
+ // Calculate the date range
112
+ const dateAgo = new Date ( ) ;
113
+ dateAgo . setDate ( dateAgo . getDate ( ) - numberOfDaysAgo ) ;
114
+ const formattedDateAgo = dateAgo . toISOString ( ) ; // ISO8601 format
115
+
116
+ // Construct the SQL query with parameterized query
117
+ queryText = {
118
+ text : `
119
+ SELECT DATE_TRUNC('week', created_at) AS week, COUNT(*) AS count
120
+ FROM incs
121
+ WHERE created_at >= $1
122
+ GROUP BY week
123
+ ORDER BY week;
124
+ ` ,
125
+ values : [ formattedDateAgo ] ,
126
+ } ;
127
+ }
116
128
117
- return await client . query ( queryText ) ;
129
+ return await client . query ( queryText ) ;
130
+ }
131
+ catch ( err ) {
132
+ console . error ( "Error fetching incs" , err ) ;
133
+ }
118
134
}
119
135
120
136
export async function getCategoriesArray ( ) {
0 commit comments