Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions controllers/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done , please check .

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}`);
Expand Down Expand Up @@ -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 : [],
Expand Down Expand Up @@ -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);
Expand All @@ -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";
}
Comment on lines +318 to +320
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Use consistent approach for task status transformation.

While this implementation works, it directly mutates the taskData object instead of creating a new object like in the other functions. This inconsistency in approach could make the code harder to maintain.

Consider using the same pattern as the other functions for consistency:

- if (taskData.status === "COMPLETED") {
-   taskData.status = "DONE";
- }
+ if (taskData.status === "COMPLETED") {
+   taskData = { ...taskData, status: "DONE" };
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (taskData.status === "COMPLETED") {
taskData.status = "DONE";
}
if (taskData.status === "COMPLETED") {
taskData = { ...taskData, status: "DONE" };
}

return res.json({
message: "task returned successfully",
taskData: { ...taskData, dependsOn: dependencyDocReference },
Expand Down
8 changes: 4 additions & 4 deletions test/integration/tasks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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;
}
});
Expand Down Expand Up @@ -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")
Expand All @@ -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();
});
Expand Down
Loading