mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Added option for getting isDue field for specified date
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import moment from 'moment';
|
||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
} from '../../../../helpers/api-integration/v3';
|
} from '../../../../helpers/api-integration/v3';
|
||||||
@@ -127,4 +128,26 @@ describe('GET /tasks/user', () => {
|
|||||||
let allCompletedTodos = await user.get('/tasks/user?type=_allCompletedTodos');
|
let allCompletedTodos = await user.get('/tasks/user?type=_allCompletedTodos');
|
||||||
expect(allCompletedTodos.length).to.equal(numberOfTodos);
|
expect(allCompletedTodos.length).to.equal(numberOfTodos);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns dailies with isDue for the date specified', async () => {
|
||||||
|
let startDate = moment().subtract('1', 'days').toDate();
|
||||||
|
let createdTasks = await user.post('/tasks/user', [
|
||||||
|
{
|
||||||
|
text: 'test daily',
|
||||||
|
type: 'daily',
|
||||||
|
startDate,
|
||||||
|
frequency: 'daily',
|
||||||
|
everyX: 2,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
let dailys = await user.get('/tasks/user?type=dailys');
|
||||||
|
|
||||||
|
expect(dailys.length).to.be.at.least(1);
|
||||||
|
expect(dailys[0]._id).to.equal(createdTasks._id);
|
||||||
|
expect(dailys[0].isDue).to.be.false;
|
||||||
|
|
||||||
|
let dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${startDate}`);
|
||||||
|
expect(dailys2[0]._id).to.equal(createdTasks._id);
|
||||||
|
expect(dailys2[0].isDue).to.be.true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -272,8 +272,9 @@ api.getUserTasks = {
|
|||||||
if (validationErrors) throw validationErrors;
|
if (validationErrors) throw validationErrors;
|
||||||
|
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
let dueDate = req.query.dueDate;
|
||||||
|
|
||||||
let tasks = await getTasks(req, res, {user});
|
let tasks = await getTasks(req, res, {user, dueDate});
|
||||||
return res.respond(200, tasks);
|
return res.respond(200, tasks);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import moment from 'moment';
|
||||||
import * as Tasks from '../models/task';
|
import * as Tasks from '../models/task';
|
||||||
import {
|
import {
|
||||||
BadRequest,
|
BadRequest,
|
||||||
@@ -22,13 +23,16 @@ async function _validateTaskAlias (tasks, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setNextDue (task, user) {
|
export function setNextDue (task, user, dueDateOption) {
|
||||||
if (task.type !== 'daily') return;
|
if (task.type !== 'daily') return;
|
||||||
|
|
||||||
|
let dateTaskIsDue = Date.now();
|
||||||
|
if (dueDateOption) dateTaskIsDue = moment(dueDateOption);
|
||||||
|
console.log(dueDateOption)
|
||||||
let optionsForShouldDo = user.preferences.toObject();
|
let optionsForShouldDo = user.preferences.toObject();
|
||||||
task.isDue = shared.shouldDo(Date.now(), task, optionsForShouldDo);
|
task.isDue = shared.shouldDo(dateTaskIsDue, task, optionsForShouldDo);
|
||||||
optionsForShouldDo.nextDue = true;
|
optionsForShouldDo.nextDue = true;
|
||||||
let nextDue = shared.shouldDo(Date.now(), task, optionsForShouldDo);
|
let nextDue = shared.shouldDo(dateTaskIsDue, task, optionsForShouldDo);
|
||||||
if (nextDue && nextDue.length > 0) {
|
if (nextDue && nextDue.length > 0) {
|
||||||
task.nextDue = nextDue.map((dueDate) => {
|
task.nextDue = nextDue.map((dueDate) => {
|
||||||
return dueDate.toISOString();
|
return dueDate.toISOString();
|
||||||
@@ -120,6 +124,7 @@ export async function getTasks (req, res, options = {}) {
|
|||||||
user,
|
user,
|
||||||
challenge,
|
challenge,
|
||||||
group,
|
group,
|
||||||
|
dueDate,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
let query = {userId: user._id};
|
let query = {userId: user._id};
|
||||||
@@ -185,6 +190,8 @@ export async function getTasks (req, res, options = {}) {
|
|||||||
} else {
|
} else {
|
||||||
orderedTasks[i] = task;
|
orderedTasks[i] = task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dueDate) setNextDue(task, user, dueDate);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove empty values from the array and add any unordered task
|
// Remove empty values from the array and add any unordered task
|
||||||
|
|||||||
Reference in New Issue
Block a user