From fd038bd1508b1fbcf29f15f225abb1cc21eab408 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 8 Aug 2023 13:44:21 -0500 Subject: [PATCH] fix(groups): redirect guild url to group plan --- .../archive/2023/20230808_guild_gems_fix.js | 62 +++++++++++++++++++ ...dder.js => 20230808_veteran_pet_ladder.js} | 4 +- website/client/src/router/index.js | 15 +++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 migrations/archive/2023/20230808_guild_gems_fix.js rename migrations/archive/2023/{20230801_veteran_pet_ladder.js => 20230808_veteran_pet_ladder.js} (97%) diff --git a/migrations/archive/2023/20230808_guild_gems_fix.js b/migrations/archive/2023/20230808_guild_gems_fix.js new file mode 100644 index 0000000000..e51bfc3086 --- /dev/null +++ b/migrations/archive/2023/20230808_guild_gems_fix.js @@ -0,0 +1,62 @@ +/* eslint-disable no-console */ +import { model as User } from '../../../website/server/models/user'; +import { TransactionModel as Transaction } from '../../../website/server/models/transaction'; + +const transactionsPerRun = 500; +const progressCount = 1000; +const transactionsQuery = { + transactionType: 'create_guild', + amount: { $gt: 0 }, +}; + +let count = 0; +async function updateTransaction (transaction) { + count++; + if (count % progressCount === 0) { + console.warn(`${count} ${transaction._id}`); + } + + const leader = await User + .findOne({ _id: transaction.userId }) + .select({ _id: true }) + .exec(); + + if (!leader) { + return console.warn(`User not found for transaction ${transaction._id}`); + } + + return leader.updateOne( + { $inc: { balance: transaction.amount }}, + ).exec(); +} + +export default async function processTransactions () { + const transactionFields = { + _id: 1, + userId: 1, + currency: 1, + amount: 1, + }; + + while (true) { // eslint-disable-line no-constant-condition + const foundTransactions = await Transaction // eslint-disable-line no-await-in-loop + .find(transactionsQuery) + .limit(transactionsPerRun) + .sort({ _id: 1 }) + .select(transactionFields) + .lean() + .exec(); + + if (foundTransactions.length === 0) { + console.warn('All appropriate transactions found and modified.'); + console.warn(`\n${count} transactions processed\n`); + break; + } else { + transactionsQuery._id = { + $gt: foundTransactions[foundTransactions.length - 1], + }; + } + + await Promise.all(foundTransactions.map(txn => updateTransaction(txn))); // eslint-disable-line no-await-in-loop + } +}; diff --git a/migrations/archive/2023/20230801_veteran_pet_ladder.js b/migrations/archive/2023/20230808_veteran_pet_ladder.js similarity index 97% rename from migrations/archive/2023/20230801_veteran_pet_ladder.js rename to migrations/archive/2023/20230808_veteran_pet_ladder.js index 23b87ec215..fa64363cff 100644 --- a/migrations/archive/2023/20230801_veteran_pet_ladder.js +++ b/migrations/archive/2023/20230808_veteran_pet_ladder.js @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -const MIGRATION_NAME = '20230801_veteran_pet_ladder'; +const MIGRATION_NAME = '20230808_veteran_pet_ladder'; import { model as User } from '../../../website/server/models/user'; const progressCount = 1000; @@ -110,7 +110,7 @@ async function updateUser (user) { export default async function processUsers () { let query = { migration: {$ne: MIGRATION_NAME}, - 'auth.timestamps.loggedin': { $gt: new Date('2023-07-01') }, + // 'auth.timestamps.loggedin': { $gt: new Date('2023-07-08') }, }; const fields = { diff --git a/website/client/src/router/index.js b/website/client/src/router/index.js index b9921675d2..7b4ce20bfe 100644 --- a/website/client/src/router/index.js +++ b/website/client/src/router/index.js @@ -460,6 +460,21 @@ router.beforeEach(async (to, from, next) => { }); } + // Redirect from Guild link to Group Plan where possible + if (to.name === 'guild') { + await store.dispatch('guilds:getGroupPlans'); + const { groupPlans } = store.state; + const groupPlanIds = groupPlans.data.map(groupPlan => groupPlan._id); + if (groupPlanIds.indexOf(to.params.groupId) !== -1) { + return next({ + name: 'groupPlanDetailInformation', + params: { + groupId: to.params.groupId, + }, + }); + } + } + // Redirect old challenge urls if (to.hash.indexOf('#/options/groups/challenges/') !== -1) { const splits = to.hash.split('/');