-
Notifications
You must be signed in to change notification settings - Fork 273
Chore: Update API response to replace task status "COMPLETED" with "DONE" #2410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 5 commits
5b6a72c
887b557
4cb3380
65c84a7
77028e7
b37d902
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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}`); | ||||||||||||||
|
@@ -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"; | ||||||||||||||
} | ||||||||||||||
Comment on lines
+318
to
+320
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||
return res.json({ | ||||||||||||||
message: "task returned successfully", | ||||||||||||||
taskData: { ...taskData, dependsOn: dependencyDocReference }, | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment
There was a problem hiding 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 .