diff --git a/controllers/tasks.js b/controllers/tasks.js index ca1557a7e..39ef4a3d2 100644 --- a/controllers/tasks.js +++ b/controllers/tasks.js @@ -251,20 +251,32 @@ const getUserTasks = async (req, res) => { * @param req {Object} - Express request object * @param res {Object} - Express response object */ + +/** + * @deprecated + * WARNING: This API endpoint is being deprecated and will be removed in future versions. + * Please use the updated API endpoint: `/tasks/:username` for retrieving user's task details. + * + * This API is kept temporarily for backward compatibility. + */ + const getSelfTasks = async (req, res) => { try { const { username } = req.userData; - if (username) { - if (req.query.completed) { - const allCompletedTasks = await tasks.fetchUserCompletedTasks(username); - return res.json(allCompletedTasks); - } else { - const allTasks = await tasks.fetchSelfTasks(username); - return res.json(allTasks); - } + if (!username) { + return res.boom.notFound("User doesn't exist"); } - return res.boom.notFound("User doesn't exist"); + + const tasksData = req.query.completed + ? await tasks.fetchUserCompletedTasks(username) + : await tasks.fetchSelfTasks(username); + + res.set( + "X-Deprecation-Warning", + "WARNING: This endpoint is deprecated and will be removed in the future. Please use /tasks/:username to get the task details." + ); + return res.json(tasksData); } catch (err) { logger.error(`Error while fetching tasks: ${err}`); return res.boom.badImplementation(INTERNAL_SERVER_ERROR); diff --git a/routes/tasks.js b/routes/tasks.js index 5596f982c..99c2fca6e 100644 --- a/routes/tasks.js +++ b/routes/tasks.js @@ -35,6 +35,7 @@ const enableDevModeMiddleware = (req, res, next) => { router.get("/", getTasksValidator, cacheResponse({ invalidationKey: ALL_TASKS, expiry: 10 }), tasks.fetchTasks); router.get("/self", authenticate, tasks.getSelfTasks); + router.get("/overdue", authenticate, authorizeRoles([SUPERUSER]), tasks.overdueTasks); router.post( "/", @@ -54,6 +55,7 @@ router.patch( ); router.get("/:id/details", tasks.getTask); router.get("/:username", tasks.getUserTasks); + router.patch( "/self/:id", authenticate, diff --git a/test/integration/tasks.test.js b/test/integration/tasks.test.js index 74d691e4d..550618dda 100644 --- a/test/integration/tasks.test.js +++ b/test/integration/tasks.test.js @@ -583,6 +583,10 @@ describe("Tasks", function () { return done; } expect(res).to.have.status(200); + expect(res).to.have.header( + "X-Deprecation-Warning", + "WARNING: This endpoint is deprecated and will be removed in the future. Please use /tasks/:username to get the task details." + ); expect(res.body).to.be.a("array"); expect(res.body[0].status).to.equal(COMPLETED); @@ -630,6 +634,10 @@ describe("Tasks", function () { .get("/tasks/self") .set("cookie", `${cookieName}=${authService.generateAuthToken({ userId: assignedUser })}`); expect(res).to.have.status(200); + expect(res).to.have.header( + "X-Deprecation-Warning", + "WARNING: This endpoint is deprecated and will be removed in the future. Please use /tasks/:username to get the task details." + ); expect(res.body).to.be.a("array"); expect([taskId1, taskId2]).to.include(taskId1); });