mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
round priority on update too (#10186)
* round priority on update too * move the fix to Task sanitizeTransform * refactor the task.priority parsing
This commit is contained in:
@@ -296,6 +296,16 @@ describe('PUT /tasks/:id', () => {
|
|||||||
|
|
||||||
expect(fetchedDaily.text).to.eql('saved');
|
expect(fetchedDaily.text).to.eql('saved');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// This is a special case for iOS requests
|
||||||
|
it('will round a priority (difficulty)', async () => {
|
||||||
|
daily = await user.put(`/tasks/${daily._id}`, {
|
||||||
|
alias: 'alias',
|
||||||
|
priority: 0.10000000000005,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(daily.priority).to.eql(0.1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('habits', () => {
|
context('habits', () => {
|
||||||
|
|||||||
@@ -458,7 +458,6 @@ api.updateTask = {
|
|||||||
let oldCheckList = task.checklist;
|
let oldCheckList = task.checklist;
|
||||||
// we have to convert task to an object because otherwise things don't get merged correctly. Bad for performances?
|
// we have to convert task to an object because otherwise things don't get merged correctly. Bad for performances?
|
||||||
let [updatedTaskObj] = common.ops.updateTask(task.toObject(), req);
|
let [updatedTaskObj] = common.ops.updateTask(task.toObject(), req);
|
||||||
|
|
||||||
// Sanitize differently user tasks linked to a challenge
|
// Sanitize differently user tasks linked to a challenge
|
||||||
let sanitizedObj;
|
let sanitizedObj;
|
||||||
|
|
||||||
@@ -471,6 +470,7 @@ api.updateTask = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_.assign(task, sanitizedObj);
|
_.assign(task, sanitizedObj);
|
||||||
|
|
||||||
// console.log(task.modifiedPaths(), task.toObject().repeat === tep)
|
// console.log(task.modifiedPaths(), task.toObject().repeat === tep)
|
||||||
// repeat is always among modifiedPaths because mongoose changes the other of the keys when using .toObject()
|
// repeat is always among modifiedPaths because mongoose changes the other of the keys when using .toObject()
|
||||||
// see https://github.com/Automattic/mongoose/issues/2749
|
// see https://github.com/Automattic/mongoose/issues/2749
|
||||||
@@ -481,7 +481,6 @@ api.updateTask = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setNextDue(task, user);
|
setNextDue(task, user);
|
||||||
|
|
||||||
let savedTask = await task.save();
|
let savedTask = await task.save();
|
||||||
|
|
||||||
if (group && task.group.id && task.group.assignedUsers.length > 0) {
|
if (group && task.group.id && task.group.assignedUsers.length > 0) {
|
||||||
|
|||||||
@@ -89,11 +89,6 @@ export async function createTasks (req, res, options = {}) {
|
|||||||
let taskType = taskData.type;
|
let taskType = taskData.type;
|
||||||
let newTask = new Tasks[taskType](Tasks.Task.sanitize(taskData));
|
let newTask = new Tasks[taskType](Tasks.Task.sanitize(taskData));
|
||||||
|
|
||||||
// Attempt to round priority
|
|
||||||
if (newTask.priority && !Number.isNaN(Number.parseFloat(newTask.priority))) {
|
|
||||||
newTask.priority = Number(newTask.priority.toFixed(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (challenge) {
|
if (challenge) {
|
||||||
newTask.challenge.id = challenge.id;
|
newTask.challenge.id = challenge.id;
|
||||||
} else if (group) {
|
} else if (group) {
|
||||||
|
|||||||
@@ -131,6 +131,14 @@ TaskSchema.plugin(baseModel, {
|
|||||||
delete taskObj.value;
|
delete taskObj.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (taskObj.priority) {
|
||||||
|
let parsedFloat = Number.parseFloat(taskObj.priority);
|
||||||
|
|
||||||
|
if (!Number.isNaN(parsedFloat)) {
|
||||||
|
taskObj.priority = parsedFloat.toFixed(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return taskObj;
|
return taskObj;
|
||||||
},
|
},
|
||||||
private: [],
|
private: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user