mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Merge branch 'release' into develop
This commit is contained in:
@@ -13,10 +13,10 @@ import { // eslint-disable-line import/no-cycle
|
||||
model as Group,
|
||||
basicFields as basicGroupFields,
|
||||
} from '../../models/group';
|
||||
import { model as User } from '../../models/user'; // eslint-disable-line import/no-cycle
|
||||
import {
|
||||
NotAuthorized,
|
||||
NotFound,
|
||||
TooManyRequests,
|
||||
} from '../errors';
|
||||
import shared from '../../../common';
|
||||
import { sendNotification as sendPushNotification } from '../pushNotifications'; // eslint-disable-line import/no-cycle
|
||||
@@ -92,19 +92,9 @@ async function prepareSubscriptionValues (data) {
|
||||
let emailType = 'subscription-begins';
|
||||
let recipientIsSubscribed = recipient.isSubscribed();
|
||||
|
||||
if (data.user && !data.gift && !data.groupId) {
|
||||
const unlockedUser = await User.findOneAndUpdate(
|
||||
{
|
||||
_id: data.user._id,
|
||||
$or: [
|
||||
{ _subSignature: 'NOT_RUNNING' },
|
||||
{ _subSignature: { $exists: false } },
|
||||
],
|
||||
},
|
||||
{ $set: { _subSignature: 'SUB_IN_PROGRESS' } },
|
||||
);
|
||||
if (!unlockedUser) {
|
||||
throw new NotFound('User not found or subscription already processing.');
|
||||
if (data.user && !data.gift && !data.groupId && data.customerId !== 'group-plan') {
|
||||
if (moment().diff(data.user.purchased.plan.dateUpdated, 'minutes') < 3) {
|
||||
throw new TooManyRequests('Subscription already processed, likely duplicate request');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,6 +346,10 @@ async function createSubscription (data) {
|
||||
}
|
||||
}
|
||||
|
||||
if (group) await group.save();
|
||||
if (data.user && data.user.isModified()) await data.user.save();
|
||||
if (data.gift) await data.gift.member.save();
|
||||
|
||||
slack.sendSubscriptionNotification({
|
||||
buyer: {
|
||||
id: data.user._id,
|
||||
@@ -372,24 +366,6 @@ async function createSubscription (data) {
|
||||
groupId,
|
||||
autoRenews,
|
||||
});
|
||||
|
||||
if (group) {
|
||||
await group.save();
|
||||
}
|
||||
if (data.user) {
|
||||
if (data.user.isModified()) {
|
||||
await data.user.save();
|
||||
}
|
||||
if (!data.gift && !data.groupId) {
|
||||
await User.findOneAndUpdate(
|
||||
{ _id: data.user._id },
|
||||
{ $set: { _subSignature: 'NOT_RUNNING' } },
|
||||
);
|
||||
}
|
||||
}
|
||||
if (data.gift) {
|
||||
await data.gift.member.save();
|
||||
}
|
||||
}
|
||||
|
||||
// Cancels a subscription or group plan, setting termination to happen later
|
||||
|
||||
Reference in New Issue
Block a user