fix(tasks): always prune __v and add id (#15301)

Co-authored-by: Sabe Jones <sabe@habitica.com>
This commit is contained in:
Sabe Jones
2024-08-28 15:05:34 -05:00
committed by GitHub
parent 83a430afad
commit 06a59bfe03

View File

@@ -252,6 +252,13 @@ async function getTasks (req, res, options = {}) {
const tasks = await mQuery.lean().exec();
// Ensure we always include the "id" variant of "_id", and not the version counter
tasks.forEach(task => {
task.id = task._id;
delete task.__v;
});
// Calculate due dates for Dailies
if (dueDate) {
tasks.forEach(task => {
setNextDue(task, user, dueDate);
@@ -288,8 +295,6 @@ async function getTasks (req, res, options = {}) {
tasks.forEach((task, index) => {
const taskId = task._id;
task.id = task._id;
delete task.__v;
const i = order[index] === taskId ? index : order.indexOf(taskId);
if (i === -1) {
unorderedTasks.push(task);