fix(groups): redirect guild url to group plan

This commit is contained in:
SabreCat 2023-08-08 13:44:21 -05:00
parent bb7e0e22ec
commit fd038bd150
3 changed files with 79 additions and 2 deletions

View file

@ -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
}
};

View file

@ -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 = {

View file

@ -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('/');