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');
|
||||
});
|
||||
|
||||
// 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', () => {
|
||||
|
||||
@@ -458,7 +458,6 @@ api.updateTask = {
|
||||
let oldCheckList = task.checklist;
|
||||
// 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);
|
||||
|
||||
// Sanitize differently user tasks linked to a challenge
|
||||
let sanitizedObj;
|
||||
|
||||
@@ -471,6 +470,7 @@ api.updateTask = {
|
||||
}
|
||||
|
||||
_.assign(task, sanitizedObj);
|
||||
|
||||
// console.log(task.modifiedPaths(), task.toObject().repeat === tep)
|
||||
// repeat is always among modifiedPaths because mongoose changes the other of the keys when using .toObject()
|
||||
// see https://github.com/Automattic/mongoose/issues/2749
|
||||
@@ -481,7 +481,6 @@ api.updateTask = {
|
||||
}
|
||||
|
||||
setNextDue(task, user);
|
||||
|
||||
let savedTask = await task.save();
|
||||
|
||||
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 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) {
|
||||
newTask.challenge.id = challenge.id;
|
||||
} else if (group) {
|
||||
|
||||
@@ -131,6 +131,14 @@ TaskSchema.plugin(baseModel, {
|
||||
delete taskObj.value;
|
||||
}
|
||||
|
||||
if (taskObj.priority) {
|
||||
let parsedFloat = Number.parseFloat(taskObj.priority);
|
||||
|
||||
if (!Number.isNaN(parsedFloat)) {
|
||||
taskObj.priority = parsedFloat.toFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
return taskObj;
|
||||
},
|
||||
private: [],
|
||||
|
||||
Reference in New Issue
Block a user