Skip to content

Commit f1ea79e

Browse files
rishirishhhvikasosmiumRahulGoyal-techAchintya-Chatterjeeprakashchoudhary07
authored
fix: deprecated GET task/self (#2284)
* 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]>
1 parent c31d7db commit f1ea79e

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

controllers/tasks.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,32 @@ const getUserTasks = async (req, res) => {
251251
* @param req {Object} - Express request object
252252
* @param res {Object} - Express response object
253253
*/
254+
255+
/**
256+
* @deprecated
257+
* WARNING: This API endpoint is being deprecated and will be removed in future versions.
258+
* Please use the updated API endpoint: `/tasks/:username` for retrieving user's task details.
259+
*
260+
* This API is kept temporarily for backward compatibility.
261+
*/
262+
254263
const getSelfTasks = async (req, res) => {
255264
try {
256265
const { username } = req.userData;
257266

258-
if (username) {
259-
if (req.query.completed) {
260-
const allCompletedTasks = await tasks.fetchUserCompletedTasks(username);
261-
return res.json(allCompletedTasks);
262-
} else {
263-
const allTasks = await tasks.fetchSelfTasks(username);
264-
return res.json(allTasks);
265-
}
267+
if (!username) {
268+
return res.boom.notFound("User doesn't exist");
266269
}
267-
return res.boom.notFound("User doesn't exist");
270+
271+
const tasksData = req.query.completed
272+
? await tasks.fetchUserCompletedTasks(username)
273+
: await tasks.fetchSelfTasks(username);
274+
275+
res.set(
276+
"X-Deprecation-Warning",
277+
"WARNING: This endpoint is deprecated and will be removed in the future. Please use /tasks/:username to get the task details."
278+
);
279+
return res.json(tasksData);
268280
} catch (err) {
269281
logger.error(`Error while fetching tasks: ${err}`);
270282
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);

routes/tasks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const enableDevModeMiddleware = (req, res, next) => {
3535

3636
router.get("/", getTasksValidator, cacheResponse({ invalidationKey: ALL_TASKS, expiry: 10 }), tasks.fetchTasks);
3737
router.get("/self", authenticate, tasks.getSelfTasks);
38+
3839
router.get("/overdue", authenticate, authorizeRoles([SUPERUSER]), tasks.overdueTasks);
3940
router.post(
4041
"/",
@@ -54,6 +55,7 @@ router.patch(
5455
);
5556
router.get("/:id/details", tasks.getTask);
5657
router.get("/:username", tasks.getUserTasks);
58+
5759
router.patch(
5860
"/self/:id",
5961
authenticate,

test/integration/tasks.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ describe("Tasks", function () {
583583
return done;
584584
}
585585
expect(res).to.have.status(200);
586+
expect(res).to.have.header(
587+
"X-Deprecation-Warning",
588+
"WARNING: This endpoint is deprecated and will be removed in the future. Please use /tasks/:username to get the task details."
589+
);
586590
expect(res.body).to.be.a("array");
587591
expect(res.body[0].status).to.equal(COMPLETED);
588592

@@ -630,6 +634,10 @@ describe("Tasks", function () {
630634
.get("/tasks/self")
631635
.set("cookie", `${cookieName}=${authService.generateAuthToken({ userId: assignedUser })}`);
632636
expect(res).to.have.status(200);
637+
expect(res).to.have.header(
638+
"X-Deprecation-Warning",
639+
"WARNING: This endpoint is deprecated and will be removed in the future. Please use /tasks/:username to get the task details."
640+
);
633641
expect(res.body).to.be.a("array");
634642
expect([taskId1, taskId2]).to.include(taskId1);
635643
});

0 commit comments

Comments
 (0)