mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
v3 adapt v2: fix tags _id, stickyHeader and unlocking
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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}});
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user