v3 adapt v2: fix tags _id, stickyHeader and unlocking

This commit is contained in:
Matteo Pagliazzi
2016-05-01 12:51:32 +02:00
parent 6380161321
commit f5144fddaa
7 changed files with 20 additions and 13 deletions

View File

@@ -44,9 +44,11 @@ module.exports = function unlock (user, req = {}, analytics) {
if (alreadyOwnedItems === setPaths.length) {
throw new NotAuthorized(i18n.t('alreadyUnlocked', req.language));
} else if (alreadyOwnedItems > 0) {
// TODO write math formula to check if buying the full set is cheaper than the items individually
// (item cost * number of remaining items) < setCost`
} /* else if (alreadyOwnedItems > 0) {
throw new NotAuthorized(i18n.t('alreadyUnlockedPart', req.language));
}
} */
} else {
alreadyOwns = _.get(user, `purchased.${path}`) === true;
}

View File

@@ -54,7 +54,8 @@ describe('shared.ops.unlock', () => {
}
});
it('returns an error when user already owns items in a full set', (done) => {
// disabled untill fully implemente
xit('returns an error when user already owns items in a full set', (done) => {
try {
unlock(user, {query: {path: unlockPath}});
unlock(user, {query: {path: unlockPath}});

View File

@@ -988,6 +988,7 @@ api.batchUpdate = function(req, res, next) {
response = transformedData;
response.todos = shared.preenTodos(response.todos);
response.wasModified = true;
res.status(200).json(response);
});
// return only the version number

View File

@@ -4,6 +4,7 @@ import objectPath from 'object-path'; // TODO use lodash's unset once v4 is out
import _ from 'lodash';
module.exports = function baseModel (schema, options = {}) {
if (options._id !== false) {
schema.add({
_id: {
type: String,
@@ -11,6 +12,7 @@ module.exports = function baseModel (schema, options = {}) {
validate: [validator.isUUID, 'Invalid uuid.'],
},
});
}
if (options.timestamps) {
schema.add({

View File

@@ -6,7 +6,6 @@ import validator from 'validator';
let Schema = mongoose.Schema;
export let schema = new Schema({
_id: false, // use id not _id
id: {
type: String,
default: uuid,
@@ -17,10 +16,12 @@ export let schema = new Schema({
}, {
strict: true,
minimize: false, // So empty objects are returned
_id: false, // use id instead of _id
});
schema.plugin(baseModel, {
noSet: ['_id', 'id', 'challenge'],
_id: false, // use id instead of _id
});
export let model = mongoose.model('Tag', schema);

View File

@@ -760,7 +760,7 @@ schema.methods.addTasksToUser = function addTasksToUser (tasks) {
obj.tags = obj.tags.map(tag => {
return {
id: tag._id,
id: tag.id,
name: tag.name,
challenge: tag.challenge,
};