v3: first review of common code and task models

This commit is contained in:
Matteo Pagliazzi
2016-04-12 19:30:39 +02:00
parent 004b032084
commit 6458796a36
14 changed files with 40 additions and 45 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import _ from 'lodash';
// TODO remove completely, use _.get
// TODO remove completely, use _.get, only used in client
module.exports = function dotGet (user, path) {
return _.get(user, path);
+1 -1
View File
@@ -7,7 +7,7 @@ import _ from 'lodash';
Angular sets object properties directly - in which case, this function will be used.
*/
// TODO use directly _.set and remove this fn
// TODO use directly _.set and remove this fn, only used in client
module.exports = function dotSet (user, path, val) {
return _.set(user, path, val);
-11
View File
@@ -221,7 +221,6 @@ api.wrap = function wrapUser (user, main = true) {
user._wrapped = true;
// Make markModified available on the client side as a noop function
// TODO move to client?
if (!user.markModified) {
user.markModified = function noopMarkModified () {};
}
@@ -305,14 +304,4 @@ api.wrap = function wrapUser (user, main = true) {
return computed;
},
});
if (typeof window !== 'undefined') {
// TODO kept for compatibility with the client that relies on v2, remove once the client is adapted
Object.defineProperty(user, 'tasks', {
get () {
let tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards);
return _.object(_.pluck(tasks, 'id'), tasks);
},
});
}
};
+1 -1
View File
@@ -1,5 +1,5 @@
import _ from 'lodash';
// TODO remove completely
// TODO remove completely, only used in client
module.exports = _.get;
+1 -1
View File
@@ -1,5 +1,5 @@
import _ from 'lodash';
// TODO remove completely
// TODO remove completely, only used in client
module.exports = _.set;
+1 -2
View File
@@ -1,8 +1,7 @@
import moment from 'moment';
import _ from 'lodash';
// TODO used only in v2 client
// TODO test
// TODO used only in v2
module.exports = function preenTodos (tasks) {
return _.filter(tasks, (t) => {
+1 -2
View File
@@ -6,7 +6,6 @@ import moment from 'moment';
// sending up to the server for performance
// TODO move to client code?
// TODO test?
const tasksTypes = ['habit', 'daily', 'todo', 'reward'];
@@ -17,7 +16,7 @@ module.exports = function taskDefaults (task = {}) {
let defaultId = uuid();
let defaults = {
_id: defaultId, // TODO convert all occurencies of id to _id
_id: defaultId,
text: task._id || defaultId,
notes: '',
tags: [],
+1 -1
View File
@@ -197,7 +197,7 @@ module.exports = function scoreTask (options = {}, req = {}) {
// Add history entry, even more than 1 per day
task.history.push({
date: Number(new Date()), // TODO are we going to cast history entries?
date: Number(new Date()),
value: task.value,
});
} else if (task.type === 'daily') {
+4 -5
View File
@@ -1,7 +1,6 @@
import i18n from '../i18n';
import _ from 'lodash';
import splitWhitespace from '../libs/splitWhitespace';
import dotSet from '../libs/dotSet';
import {
NotAuthorized,
BadRequest,
@@ -37,11 +36,11 @@ module.exports = function unlock (user, req = {}, analytics) {
if (isFullSet) {
_.each(path.split(','), function markItemsAsPurchased (pathPart) {
if (path.indexOf('gear.') !== -1) {
dotSet(user, pathPart, true);
_.set(user, pathPart, true);
return true;
}
dotSet(user, `purchased.${pathPart}`, true);
_.set(user, `purchased.${pathPart}`, true);
return true;
});
} else {
@@ -52,11 +51,11 @@ module.exports = function unlock (user, req = {}, analytics) {
if (key === 'background' && value === user.preferences.background) {
value = '';
}
dotSet(user, `preferences.${key}`, value);
_.set(user, `preferences.${key}`, value);
throw new NotAuthorized(i18n.t('alreadyUnlocked', req.language));
}
dotSet(user, `purchased.${path}`, true);
_.set(user, `purchased.${path}`, true);
}
if (path.indexOf('gear.') === -1) {