-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatsController.js
More file actions
38 lines (33 loc) · 1.11 KB
/
statsController.js
File metadata and controls
38 lines (33 loc) · 1.11 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
const wakatimeService = require('./wakatimeService');
/**
* Endpoint handler to fetch raw duration data for a specific day.
* GET /api/durations?date=YYYY-MM-DD&project=optional
*/
const getDurations = async (req, res, next) => {
try {
const { date, project } = req.query;
if (!date) {
return res.status(400).json({ message: "Date parameter (YYYY-MM-DD) is required." });
}
// Fetch durations data using 'current' user slug
const durationsData = await wakatimeService.fetchWakaTimeDurations(
date,
'current',
project
);
// Send the complete durations data back, including start/end timestamps
res.status(200).json({
status: 'success',
requested_date: date,
data: durationsData.data, // The array of duration objects
start_time: durationsData.start,
end_time: durationsData.end
});
} catch (error) {
// Pass the error to the Express error handler in server.js
next(error);
}
};
module.exports = {
getDurations,
};