@@ -147,8 +147,10 @@ export async function update (req, res, { isV3 = false }) {
|
||||
await checkNewInputForProfanity(user, res, newBlurb);
|
||||
}
|
||||
|
||||
let groupsToMirror;
|
||||
let matchingGroupsArray;
|
||||
if (req.body['preferences.tasks.mirrorGroupTasks'] !== undefined) {
|
||||
const groupsToMirror = req.body['preferences.tasks.mirrorGroupTasks'];
|
||||
groupsToMirror = req.body['preferences.tasks.mirrorGroupTasks'];
|
||||
if (!Array.isArray(groupsToMirror)) {
|
||||
throw new BadRequest('Groups to copy tasks from must be an array.');
|
||||
}
|
||||
@@ -160,7 +162,7 @@ export async function update (req, res, { isV3 = false }) {
|
||||
}
|
||||
}
|
||||
|
||||
const matchingGroupsCount = await Groups.countDocuments({
|
||||
const matchingGroups = await Groups.find({
|
||||
_id: { $in: groupsToMirror },
|
||||
'purchased.plan.customerId': { $exists: true },
|
||||
$or: [
|
||||
@@ -168,11 +170,11 @@ export async function update (req, res, { isV3 = false }) {
|
||||
{ 'purchased.plan.dateTerminated': null },
|
||||
{ 'purchased.plan.dateTerminated': { $gt: new Date() } },
|
||||
],
|
||||
}, {
|
||||
_id: 1,
|
||||
}).exec();
|
||||
|
||||
if (matchingGroupsCount !== groupsToMirror.length) {
|
||||
throw new BadRequest('Groups to copy tasks from must have subscriptions.');
|
||||
}
|
||||
matchingGroupsArray = _.map(matchingGroups, groupRecord => groupRecord._id);
|
||||
}
|
||||
|
||||
_.each(req.body, (val, key) => {
|
||||
@@ -234,6 +236,8 @@ export async function update (req, res, { isV3 = false }) {
|
||||
if (lastNewsPost) {
|
||||
user.flags.lastNewStuffRead = lastNewsPost._id;
|
||||
}
|
||||
} else if (key === 'preferences.tasks.mirrorGroupTasks') {
|
||||
user.preferences.mirrorGroupTasks = _.intersection(groupsToMirror, matchingGroupsArray);
|
||||
} else if (acceptablePUTPaths[key]) {
|
||||
let adjustedVal = val;
|
||||
if (key === 'stats.lvl' && val > common.constants.MAX_LEVEL_HARD_CAP) {
|
||||
|
||||
Reference in New Issue
Block a user