mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix unlocking items with numbers in paths
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
NotAuthorized,
|
NotAuthorized,
|
||||||
BadRequest,
|
BadRequest,
|
||||||
} from '../libs/errors';
|
} from '../libs/errors';
|
||||||
|
import setWith from 'lodash.setwith'; // Not available in lodash 3
|
||||||
|
|
||||||
// If item is already purchased -> equip it
|
// If item is already purchased -> equip it
|
||||||
// Otherwise unlock it
|
// Otherwise unlock it
|
||||||
@@ -60,10 +61,12 @@ module.exports = function unlock (user, req = {}, analytics) {
|
|||||||
if (isFullSet) {
|
if (isFullSet) {
|
||||||
_.each(setPaths, function markItemsAsPurchased (pathPart) {
|
_.each(setPaths, function markItemsAsPurchased (pathPart) {
|
||||||
if (path.indexOf('gear.') !== -1) {
|
if (path.indexOf('gear.') !== -1) {
|
||||||
_.set(user, pathPart, true);
|
// Using Object so path[1] won't create an array but an object {path: {1: value}}
|
||||||
|
setWith(user, pathPart, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_.set(user, `purchased.${pathPart}`, true);
|
// Using Object so path[1] won't create an array but an object {path: {1: value}}
|
||||||
|
setWith(user, `purchased.${pathPart}`, true, Object);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (alreadyOwns) { // eslint-disable-line no-lonely-if
|
if (alreadyOwns) { // eslint-disable-line no-lonely-if
|
||||||
@@ -74,9 +77,11 @@ module.exports = function unlock (user, req = {}, analytics) {
|
|||||||
value = '';
|
value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
_.set(user, `preferences.${key}`, value);
|
// Using Object so path[1] won't create an array but an object {path: {1: value}}
|
||||||
|
setWith(user, `preferences.${key}`, value);
|
||||||
} else {
|
} else {
|
||||||
_.set(user, `purchased.${path}`, true);
|
// Using Object so path[1] won't create an array but an object {path: {1: value}}
|
||||||
|
setWith(user, `purchased.${path}`, true, Object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
"jade": "~1.11.0",
|
"jade": "~1.11.0",
|
||||||
"js2xmlparser": "~1.0.0",
|
"js2xmlparser": "~1.0.0",
|
||||||
"lodash": "^3.10.1",
|
"lodash": "^3.10.1",
|
||||||
|
"lodash.setwith": "^4.2.0",
|
||||||
"loggly": "~1.0.8",
|
"loggly": "~1.0.8",
|
||||||
"markdown-it": "^6.0.1",
|
"markdown-it": "^6.0.1",
|
||||||
"merge-stream": "^1.0.0",
|
"merge-stream": "^1.0.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user