From 5b6a72ca0ec05372f1f3d3edd43686de4d8c0b7e Mon Sep 17 00:00:00 2001 From: Vaishali Maheshwari <80218238+vaishalimaheshwari2000@users.noreply.github.com> Date: Wed, 30 Apr 2025 00:13:10 +0530 Subject: [PATCH 1/6] changes in controllers --- controllers/tasks.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/controllers/tasks.js b/controllers/tasks.js index 39ef4a3d26..e7683d5d66 100644 --- a/controllers/tasks.js +++ b/controllers/tasks.js @@ -159,6 +159,7 @@ const fetchTasks = async (req, res) => { }); } const filterTasks = await tasks.fetchTasks(searchParams.searchTerm); + const tasksWithRdsAssigneeInfo = await fetchTasksWithRdsAssigneeInfo(filterTasks); if (tasksWithRdsAssigneeInfo.length === 0) { return res.status(404).json({ @@ -195,9 +196,20 @@ const fetchTasks = async (req, res) => { } const paginatedTasks = await fetchPaginatedTasks({ ...transformedQuery, prev, next, userFeatureFlag }); + + const updatedData = { + ...paginatedTasks, // assuming your original JSON is stored in a variable called 'data' + tasks: paginatedTasks.tasks.map((task) => { + if (task.status === "COMPLETED") { + return { ...task, status: "DONE" }; + } + return task; + }), + }; + return res.json({ message: "Tasks returned successfully!", - ...paginatedTasks, + ...updatedData, }); } catch (err) { logger.error(`Error while fetching tasks ${err}`); @@ -230,13 +242,20 @@ const getUserTasks = async (req, res) => { } allTasks = await tasks.fetchUserTasks(username, status || []); - if (allTasks.userNotFound) { + const changeStstusallTasks = allTasks.map((task) => { + if (task.status === "COMPLETED") { + return { ...task, status: "DONE" }; + } + return task; + }); + + if (changeStstusallTasks.userNotFound) { return res.boom.notFound("User doesn't exist"); } return res.json({ message: "Tasks returned successfully!", - tasks: allTasks.length > 0 ? allTasks : [], + tasks: changeStstusallTasks.length > 0 ? allTasks : [], }); } catch (err) { logger.error(`Error while fetching tasks: ${err}`); @@ -272,11 +291,17 @@ const getSelfTasks = async (req, res) => { ? await tasks.fetchUserCompletedTasks(username) : await tasks.fetchSelfTasks(username); + const statusChangedtasksData = tasksData.map((task) => { + if (task.status === "COMPLETED") { + return { ...task, status: "DONE" }; + } + return task; + }); 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); + return res.json(statusChangedtasksData); } catch (err) { logger.error(`Error while fetching tasks: ${err}`); return res.boom.badImplementation(INTERNAL_SERVER_ERROR); @@ -290,6 +315,9 @@ const getTask = async (req, res) => { if (!taskData) { return res.boom.notFound("Task not found"); } + if (taskData.status === "COMPLETED") { + taskData.status = "DONE"; + } return res.json({ message: "task returned successfully", taskData: { ...taskData, dependsOn: dependencyDocReference }, From 887b5578fc218d308582d9a3a52b6a4a933966da Mon Sep 17 00:00:00 2001 From: Vaishali Maheshwari <80218238+vaishalimaheshwari2000@users.noreply.github.com> Date: Wed, 30 Apr 2025 00:42:34 +0530 Subject: [PATCH 2/6] changes in controllers --- controllers/tasks.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/tasks.js b/controllers/tasks.js index e7683d5d66..3e1903b6ba 100644 --- a/controllers/tasks.js +++ b/controllers/tasks.js @@ -242,20 +242,20 @@ const getUserTasks = async (req, res) => { } allTasks = await tasks.fetchUserTasks(username, status || []); - const changeStstusallTasks = allTasks.map((task) => { + allTasks = allTasks.map((task) => { if (task.status === "COMPLETED") { return { ...task, status: "DONE" }; } return task; }); - if (changeStstusallTasks.userNotFound) { + if (allTasks.userNotFound) { return res.boom.notFound("User doesn't exist"); } return res.json({ message: "Tasks returned successfully!", - tasks: changeStstusallTasks.length > 0 ? allTasks : [], + tasks: allTasks.length > 0 ? allTasks : [], }); } catch (err) { logger.error(`Error while fetching tasks: ${err}`); From 4cb338068c6a334410361f39940958dbc0f0885d Mon Sep 17 00:00:00 2001 From: Vaishali Maheshwari <80218238+vaishalimaheshwari2000@users.noreply.github.com> Date: Wed, 30 Apr 2025 02:28:26 +0530 Subject: [PATCH 3/6] changes in test cases --- test/integration/tasks.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/tasks.test.js b/test/integration/tasks.test.js index 1d384337d1..03cd0054b3 100644 --- a/test/integration/tasks.test.js +++ b/test/integration/tasks.test.js @@ -545,7 +545,7 @@ describe("Tasks", function () { it("Should get tasks with COMPLETED status task when fetching task of status Done", async function () { await tasks.updateTask( { - status: "COMPLETED", + status: "DONE", }, taskId2 ); From 65c84a7e7d709bec3317e296f676464728b562b9 Mon Sep 17 00:00:00 2001 From: Vaishali Maheshwari <80218238+vaishalimaheshwari2000@users.noreply.github.com> Date: Wed, 30 Apr 2025 21:44:47 +0530 Subject: [PATCH 4/6] resolve the test cases --- controllers/tasks.js | 8 ++++---- test/integration/tasks.test.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/controllers/tasks.js b/controllers/tasks.js index 3e1903b6ba..72c05cd96b 100644 --- a/controllers/tasks.js +++ b/controllers/tasks.js @@ -242,6 +242,10 @@ const getUserTasks = async (req, res) => { } allTasks = await tasks.fetchUserTasks(username, status || []); + if (allTasks.userNotFound) { + return res.boom.notFound("User doesn't exist"); + } + allTasks = allTasks.map((task) => { if (task.status === "COMPLETED") { return { ...task, status: "DONE" }; @@ -249,10 +253,6 @@ const getUserTasks = async (req, res) => { return task; }); - if (allTasks.userNotFound) { - return res.boom.notFound("User doesn't exist"); - } - return res.json({ message: "Tasks returned successfully!", tasks: allTasks.length > 0 ? allTasks : [], diff --git a/test/integration/tasks.test.js b/test/integration/tasks.test.js index 03cd0054b3..cfe9211e71 100644 --- a/test/integration/tasks.test.js +++ b/test/integration/tasks.test.js @@ -560,7 +560,7 @@ describe("Tasks", function () { const tasksData = res.body.tasks ?? []; let countCompletedTask = 0; tasksData.forEach((task, i) => { - if (task.status === "COMPLETED") { + if (task.status === "DONE") { countCompletedTask += 1; } }); @@ -605,10 +605,10 @@ describe("Tasks", function () { describe("GET /tasks/self", function () { it("Should return all the completed tasks of the user when query 'completed' is true", function (done) { - const { COMPLETED } = TASK_STATUS; + const { DONE } = TASK_STATUS; chai .request(app) - .get("/tasks/self?completed=true") + .get("/tasks/self?done=true") .set("cookie", `${cookieName}=${jwt}`) .end((err, res) => { if (err) { @@ -620,7 +620,7 @@ describe("Tasks", function () { "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); + expect(res.body[0].status).to.equal(DONE); return done(); }); From 77028e70f2409dd52cce861bc6bf48e58293a18f Mon Sep 17 00:00:00 2001 From: Vaishali Maheshwari <80218238+vaishalimaheshwari2000@users.noreply.github.com> Date: Wed, 30 Apr 2025 23:16:12 +0530 Subject: [PATCH 5/6] change in query param --- test/integration/tasks.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/tasks.test.js b/test/integration/tasks.test.js index cfe9211e71..9ed96d58d7 100644 --- a/test/integration/tasks.test.js +++ b/test/integration/tasks.test.js @@ -608,7 +608,7 @@ describe("Tasks", function () { const { DONE } = TASK_STATUS; chai .request(app) - .get("/tasks/self?done=true") + .get("/tasks/self?completed=true") .set("cookie", `${cookieName}=${jwt}`) .end((err, res) => { if (err) { From b37d90210804754f39f1e2978028cd23c7fe5e4c Mon Sep 17 00:00:00 2001 From: Vaishali Maheshwari <80218238+vaishalimaheshwari2000@users.noreply.github.com> Date: Thu, 1 May 2025 01:01:19 +0530 Subject: [PATCH 6/6] remove comments --- controllers/tasks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/tasks.js b/controllers/tasks.js index 72c05cd96b..38eecbf344 100644 --- a/controllers/tasks.js +++ b/controllers/tasks.js @@ -198,7 +198,7 @@ const fetchTasks = async (req, res) => { const paginatedTasks = await fetchPaginatedTasks({ ...transformedQuery, prev, next, userFeatureFlag }); const updatedData = { - ...paginatedTasks, // assuming your original JSON is stored in a variable called 'data' + ...paginatedTasks, tasks: paginatedTasks.tasks.map((task) => { if (task.status === "COMPLETED") { return { ...task, status: "DONE" };