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) { if (alreadyOwnedItems === setPaths.length) {
throw new NotAuthorized(i18n.t('alreadyUnlocked', req.language)); 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)); throw new NotAuthorized(i18n.t('alreadyUnlockedPart', req.language));
} } */
} else { } else {
alreadyOwns = _.get(user, `purchased.${path}`) === true; alreadyOwns = _.get(user, `purchased.${path}`) === true;
} }

View File

@@ -109,7 +109,7 @@ angular.module('habitrpg')
if (MOBILE_APP) Notification.push({type:'text',text:message}); if (MOBILE_APP) Notification.push({type:'text',text:message});
else Notification.text(message); else Notification.text(message);
// In the case of 200s, they're friendly alert messages like "Your pet has hatched!" - still send the op // In the case of 200s, they're friendly alert messages like "Your pet has hatched!" - still send the op
if ((err.code && err.code >= 400) || !err.code) return; if ((err.code && err.code >= 400) || !err.code) return;
} }
userServices.log({op:k, params: req.params, query:req.query, body:req.body}); userServices.log({op:k, params: req.params, query:req.query, body:req.body});
}); });

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 { try {
unlock(user, {query: {path: unlockPath}}); unlock(user, {query: {path: unlockPath}});
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 = transformedData;
response.todos = shared.preenTodos(response.todos); response.todos = shared.preenTodos(response.todos);
response.wasModified = true;
res.status(200).json(response); res.status(200).json(response);
}); });
// return only the version number // return only the version number

View File

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

View File

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