Skip to content

Commit

Permalink
⬆️ updated package dependencies
Browse files Browse the repository at this point in the history
👨‍💻 added two new API endpoints to retrieve all time entries for a project (implements [Feature request] API to fetch time entries by date and project  #218)
📚 updated API docs
  • Loading branch information
faburem committed Nov 4, 2024
1 parent d4ec3ca commit 9c5060f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 17 deletions.
25 changes: 13 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "titra",
"version": "0.99.18",
"version": "0.99.19",
"private": true,
"scripts": {
"start": "meteor run"
},
"dependencies": {
"@babel/runtime": "^7.25.9",
"@babel/runtime": "^7.26.0",
"@dashboardcode/bsmultiselect": "^1.1.18",
"@fortawesome/fontawesome-free": "^6.6.0",
"@fullcalendar/core": "6.1.15",
Expand All @@ -33,7 +33,7 @@
"jquery-serializejson": "^3.2.1",
"ldapjs": "3.0.7",
"math-expression-evaluator": "^2.0.5",
"meteor-node-stubs": "^1.2.10",
"meteor-node-stubs": "^1.2.12",
"namedavatar": "^1.2.0",
"node-emoji": "^2.1.3",
"quill-delta-to-html": "^0.12.1",
Expand Down
71 changes: 69 additions & 2 deletions server/APIroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ WebApp.handlers.use('/timeentry/create/', async (req, res, next) => {

/**
* @api {get} /timeentry/list/:date Get time entries for date
* @apiDescription list time entries for the provided date
* @apiDescription list time entries of the authorized user for the provided date
* @apiName getTimeEntriesForDate
* @apiGroup TimeEntry
*
Expand Down Expand Up @@ -139,7 +139,7 @@ WebApp.handlers.use('/timeentry/list/', async (req, res, next) => {
})
/**
* @api {get} /timeentry/daterange/:fromDate/:toDate Get time entries for daterange
* @apiDescription list time entries for the provided date range
* @apiDescription list time entries of the authorized user for the provided date range
* @apiName getTimeEntriesForDateRange
* @apiGroup TimeEntry
*
Expand Down Expand Up @@ -193,6 +193,73 @@ WebApp.handlers.use('/project/list/', async (req, res, next) => {
sendResponse(res, 200, 'Returning projects', payload)
})

/**
* @api {get} /project/timeentries/:projectId Get time entries for project
* @apiDescription List time entries for the specified project
* @apiName getTimeEntriesForProject
* @apiGroup Project
*
* @apiHeader {String} Token The authorization header Bearer API token.
* @apiParam {String} projectId The ID of the project to list time entries for.
* @apiSuccess {json} response An array of time entries for the specified project.
* @apiUse AuthError
*/
WebApp.handlers.use('/project/timeentries/', async (req, res, next) => {
const meteorUser = await checkAuthorization(req, res)
if (!meteorUser) {
return
}
const url = req._parsedUrl.pathname.split('/')
const projectId = url[3]
const payload = await Timecards.find({
projectId,
}).fetchAsync()
sendResponse(res, 200, 'Returning time entries for project', payload)
})
/**
* @api {get} /project/timeentriesfordaterange/:projectId/:fromDate/:toDate Get time entries for a project within a date range
* @apiName GetTimeEntriesForDateRange
* @apiGroup Project
*
* @apiParam {String} projectId The ID of the project.
* @apiParam {String} fromDate The start date of the range (ISO 8601 format).
* @apiParam {String} toDate The end date of the range (ISO 8601 format).
*
* @apiSuccess {Object[]} payload A list of time entries for the specified project and date range.
* @apiSuccess {String} payload.projectId The ID of the project.
* @apiSuccess {String} payload.date The date of the time entry.
* @apiSuccess {Number} payload.hours The number of hours logged.
* @apiSuccess {String} payload.description A description of the work done.
*
* @apiError (500) InvalidParameters Invalid parameters received.
*
* @apiExample {curl} Example usage:
* curl -i http://localhost:3000/project/timeentriesfordaterange/12345/2023-01-01/2023-01-31
*/
WebApp.handlers.use('/project/timeentriesfordaterange/', async (req, res, next) => {
const meteorUser = await checkAuthorization(req, res)
if (!meteorUser) {
return
}
const url = req._parsedUrl.pathname.split('/')
const projectId = url[3]
const fromDate = new Date(url[4])
const toDate = new Date(url[5])
try {
check(projectId, String)
check(fromDate, Date)
check(toDate, Date)
} catch (error) {
sendResponse(res, 500, `Invalid parameters received.${error}`)
return
}
const payload = await Timecards.find({
projectId,
date: { $gte: fromDate, $lte: toDate },
}).fetchAsync()
sendResponse(res, 200, `Returning project time entries for date range ${fromDate} to ${toDate}`, payload)
})

/**
* @api {post} /project/create/ Create a new project
* @apiDescription Creates a new titra project based on the parameters provided
Expand Down

0 comments on commit 9c5060f

Please sign in to comment.