Skip to content

Commit

Permalink
fix: deprecated GET task/self (#2284)
Browse files Browse the repository at this point in the history
* fix: deprecated GET task/self

* fix: fixed the failing test

* Update tasks.test.js

* added warning message for deprecated route

* added test cases for dev = false or when dev is not present

* added a new error message

* added error message to the controller

* changes to the error code in test

* correct warning message

* Update tasks.test.js

* Update tasks.test.js

* added new warning message

* test changes

* Merge pull request #2292 from vikasosmium/deprecate-stocks-self-GET-route

Added New Route to fetch User Stocks

* Remove user.data() in firestore data set (#2282)

* Updated set

* Added Dev Feature Flag

* Added variable for dev flag

* Update dev feature flag to be used as boolean

* Tests working of addOrUpdate feature when dev feature flag is true

---------

Co-authored-by: Achintya Chatterjee <[email protected]>
Co-authored-by: Prakash Choudhary <[email protected]>

* new route definition

minor changes

* Update tasks.js

* reverted errorMessages.ts

* reverted tasks.js controller

* reverted tasks.js router

* updated tasks.test.js

---------

Co-authored-by: Vikas Singh <[email protected]>
Co-authored-by: Rahul Goyal <[email protected]>
Co-authored-by: Achintya Chatterjee <[email protected]>
Co-authored-by: Prakash Choudhary <[email protected]>
  • Loading branch information
5 people authored Dec 18, 2024
1 parent c31d7db commit f1ea79e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
30 changes: 21 additions & 9 deletions controllers/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions routes/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"/",
Expand All @@ -54,6 +55,7 @@ router.patch(
);
router.get("/:id/details", tasks.getTask);
router.get("/:username", tasks.getUserTasks);

router.patch(
"/self/:id",
authenticate,
Expand Down
8 changes: 8 additions & 0 deletions test/integration/tasks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit f1ea79e

Please sign in to comment.