fix(subs): establish lock to prevent race condition

This commit is contained in:
SabreCat
2022-11-01 20:47:21 -05:00
parent a2d5211b00
commit aea0be3245
18 changed files with 1146 additions and 720 deletions

View File

@@ -492,7 +492,17 @@ api.updateGroup = {
if (req.body.leader !== user._id && group.hasNotCancelled()) throw new NotAuthorized(res.t('cannotChangeLeaderWithActiveGroupPlan'));
_.assign(group, _.merge(group.toObject(), Group.sanitizeUpdate(req.body)));
const handleArrays = (currentValue, updatedValue) => {
if (!_.isArray(currentValue)) {
return undefined;
}
// Previously, categories could get duplicated. By making the updated category list unique,
// the duplication issue is fixed on every group edit
return _.uniqBy(updatedValue, 'slug');
};
_.assign(group, _.mergeWith(group.toObject(), Group.sanitizeUpdate(req.body), handleArrays));
const savedGroup = await group.save();
const response = await Group.toJSONCleanChat(savedGroup, user);