Added nextDue field
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
import common from '../../../common';
|
||||
import Bluebird from 'bluebird';
|
||||
import _ from 'lodash';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import logger from '../../libs/logger';
|
||||
|
||||
const MAX_SCORE_NOTES_LENGTH = 256;
|
||||
@@ -457,7 +458,13 @@ api.updateTask = {
|
||||
}
|
||||
|
||||
if (sanitizedObj.type === 'daily') {
|
||||
task.isDue = common.shouldDo(Date.now(), sanitizedObj, user.preferences);
|
||||
let optionsForShouldDo = cloneDeep(user.preferences.toObject());
|
||||
task.isDue = common.shouldDo(Date.now(), sanitizedObj, optionsForShouldDo);
|
||||
optionsForShouldDo.nextDue = true;
|
||||
let nextDue = common.shouldDo(Date.now(), sanitizedObj, optionsForShouldDo);
|
||||
if (nextDue && nextDue.length > 0) {
|
||||
task.nextDue = nextDue;
|
||||
}
|
||||
}
|
||||
|
||||
let savedTask = await task.save();
|
||||
@@ -590,7 +597,13 @@ api.scoreTask = {
|
||||
}
|
||||
|
||||
if (task.type === 'daily') {
|
||||
task.isDue = common.shouldDo(Date.now(), task, user.preferences);
|
||||
let optionsForShouldDo = cloneDeep(user.preferences.toObject());
|
||||
task.isDue = common.shouldDo(Date.now(), task, optionsForShouldDo);
|
||||
optionsForShouldDo.nextDue = true;
|
||||
let nextDue = common.shouldDo(Date.now(), task, optionsForShouldDo);
|
||||
if (nextDue && nextDue.length > 0) {
|
||||
task.nextDue = nextDue;
|
||||
}
|
||||
}
|
||||
|
||||
let results = await Bluebird.all([
|
||||
|
||||
@@ -4,6 +4,7 @@ import { model as User } from '../models/user';
|
||||
import common from '../../common/';
|
||||
import { preenUserHistory } from '../libs/preening';
|
||||
import _ from 'lodash';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import nconf from 'nconf';
|
||||
|
||||
const CRON_SAFE_MODE = nconf.get('CRON_SAFE_MODE') === 'true';
|
||||
@@ -314,7 +315,15 @@ export function cron (options = {}) {
|
||||
value: task.value,
|
||||
});
|
||||
task.completed = false;
|
||||
task.isDue = common.shouldDo(Date.now(), task, user.preferences);
|
||||
|
||||
let optionsForShouldDo = cloneDeep(user.preferences.toObject());
|
||||
task.isDue = common.shouldDo(now, task, optionsForShouldDo);
|
||||
optionsForShouldDo.nextDue = true;
|
||||
let nextDue = common.shouldDo(now, task, optionsForShouldDo);
|
||||
|
||||
if (nextDue && nextDue.length > 0) {
|
||||
task.nextDue = nextDue;
|
||||
}
|
||||
|
||||
if (completed || scheduleMisses > 0) {
|
||||
if (task.checklist) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
} from './errors';
|
||||
import Bluebird from 'bluebird';
|
||||
import _ from 'lodash';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import shared from '../../common';
|
||||
|
||||
async function _validateTaskAlias (tasks, res) {
|
||||
@@ -64,7 +65,15 @@ export async function createTasks (req, res, options = {}) {
|
||||
newTask.userId = user._id;
|
||||
}
|
||||
|
||||
if (newTask.type === 'daily') newTask.isDue = shared.shouldDo(Date.now(), newTask, user.preferences);
|
||||
if (newTask.type === 'daily') {
|
||||
let optionsForShouldDo = cloneDeep(user.preferences.toObject());
|
||||
newTask.isDue = shared.shouldDo(Date.now(), newTask, optionsForShouldDo);
|
||||
optionsForShouldDo.nextDue = true;
|
||||
let nextDue = shared.shouldDo(Date.now(), newTask, optionsForShouldDo);
|
||||
if (nextDue && nextDue.length > 0) {
|
||||
newTask.nextDue = nextDue;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate that the task is valid and throw if it isn't
|
||||
// otherwise since we're saving user/challenge/group and task in parallel it could save the user/challenge/group with a tasksOrder that doens't match reality
|
||||
|
||||
@@ -243,6 +243,7 @@ export let DailySchema = new Schema(_.defaults({
|
||||
daysOfMonth: {type: [Number], default: []}, // Days of the month that the daily should repeat on
|
||||
weeksOfMonth: {type: [Number], default: []}, // Weeks of the month that the daily should repeat on
|
||||
isDue: {type: Boolean},
|
||||
nextDue: [{type: String}],
|
||||
}, habitDailySchema(), dailyTodoSchema()), subDiscriminatorOptions);
|
||||
export let daily = Task.discriminator('daily', DailySchema);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user