mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
* toggle pinned state of items server + client * pin quests / add pin src * add officially pinned items and api to get in app rewards * update schema and get items deatils * update pin actions to the new logic * show countBadge only with a number * extract getPinKey - pin seasonal items * togglePinned in buy-dialogs * add pinKey to shop items * wip * wip * fix path * togglePinnedItem as common.op / use in client * fix linting * pinning: getItemInfo and save in db path and type * make api more consistent, fix bugs * updates * fix bugs * update actions to current api * marketGear * change to pinType * add mystery_set to getItemInfo * fix isPinned * ignore animals * list shopItems (initial) * shopItem now has default popoverconent, itemclass and price / currency - list pinned items as rewards - attributes to gear * show buyModal for the rewards * show mystery_set icon * add info whether item is suggested * write migration, fix style issues * pin potion and armoire * make potion, armoire not unpinnable * show notes for armoire and potion, add default items for new users * show unpin notification * add/remove pinned gear on class-change * remove pinned & add new gear on purchase - refactoring pinning methods - fixes * always allow to purchase armoire * highlight item if suggested
109 lines
2.4 KiB
JavaScript
109 lines
2.4 KiB
JavaScript
var updateStore = require('../website/common/script/libs/updateStore');
|
|
var getItemInfo = require('../website/common/script/libs/getItemInfo');
|
|
|
|
var migrationName = '20170811_pinned_items.js';
|
|
var authorName = 'paglias'; // in case script author needs to know when their ...
|
|
var authorUuid = 'ed4c688c-6652-4a92-9d03-a5a79844174a'; //... own data is done
|
|
|
|
/*
|
|
* Migrate existing in app rewards lists to pinned items
|
|
*/
|
|
|
|
var monk = require('monk');
|
|
var connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE
|
|
var dbUsers = monk(connectionString).get('users', { castIds: false });
|
|
|
|
function processUsers(lastId) {
|
|
// specify a query to limit the affected users (empty for all users):
|
|
var query = {
|
|
'migration':{$ne:migrationName},
|
|
};
|
|
|
|
if (lastId) {
|
|
query._id = {
|
|
$gt: lastId
|
|
}
|
|
}
|
|
|
|
return dbUsers.find(query, {
|
|
sort: {_id: 1},
|
|
limit: 250,
|
|
})
|
|
.then(updateUsers)
|
|
.catch(function (err) {
|
|
console.log(err);
|
|
return exiting(1, 'ERROR! ' + err);
|
|
});
|
|
}
|
|
|
|
var progressCount = 1000;
|
|
var count = 0;
|
|
|
|
function updateUsers (users) {
|
|
if (!users || users.length === 0) {
|
|
console.warn('All appropriate users found and modified.');
|
|
displayData();
|
|
return;
|
|
}
|
|
|
|
var userPromises = users.map(updateUser);
|
|
var lastUser = users[users.length - 1];
|
|
|
|
return Promise.all(userPromises)
|
|
.then(function () {
|
|
processUsers(lastUser._id);
|
|
});
|
|
}
|
|
|
|
function updateUser (user) {
|
|
count++;
|
|
|
|
var set = {'migration': migrationName};
|
|
|
|
var oldRewardsList = updateStore(user);
|
|
var newPinnedItems = [
|
|
{
|
|
type: 'armoire',
|
|
path: 'armoire',
|
|
},
|
|
{
|
|
type: 'potion',
|
|
path: 'potion',
|
|
},
|
|
];
|
|
|
|
oldRewardsList.forEach(item => {
|
|
var type = 'marketGear';
|
|
|
|
var itemInfo = getItemInfo(user, 'marketGear', item);
|
|
newPinnedItems.push({
|
|
type,
|
|
path: itemInfo.path,
|
|
})
|
|
});
|
|
|
|
set.pinnedItems = newPinnedItems;
|
|
|
|
if (count % progressCount == 0) console.warn(count + ' ' + user._id);
|
|
if (user._id == authorUuid) console.warn(authorName + ' processed');
|
|
|
|
return dbUsers.update({_id: user._id}, {$set:set});
|
|
}
|
|
|
|
function displayData() {
|
|
console.warn('\n' + count + ' users processed\n');
|
|
return exiting(0);
|
|
}
|
|
|
|
function exiting(code, msg) {
|
|
code = code || 0; // 0 = success
|
|
if (code && !msg) { msg = 'ERROR!'; }
|
|
if (msg) {
|
|
if (code) { console.error(msg); }
|
|
else { console.log( msg); }
|
|
}
|
|
process.exit(code);
|
|
}
|
|
|
|
module.exports = processUsers;
|