diff --git a/controllers/tasks.js b/controllers/tasks.js index 39ef4a3d2..38eecbf34 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, + 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}`); @@ -234,6 +246,13 @@ const getUserTasks = async (req, res) => { return res.boom.notFound("User doesn't exist"); } + allTasks = allTasks.map((task) => { + if (task.status === "COMPLETED") { + return { ...task, status: "DONE" }; + } + return task; + }); + return res.json({ message: "Tasks returned successfully!", tasks: allTasks.length > 0 ? allTasks : [], @@ -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 }, diff --git a/test/integration/tasks.test.js b/test/integration/tasks.test.js index 1d384337d..9ed96d58d 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 ); @@ -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,7 +605,7 @@ 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") @@ -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(); });