mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-05-22 13:48:37 +00:00
fix(subs): roll all the way back, didn't work :(
This commit is contained in:
parent
febffb3f07
commit
15353eba8a
1 changed files with 4 additions and 35 deletions
|
|
@ -11,7 +11,6 @@ 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,
|
||||
|
|
@ -80,22 +79,6 @@ async function createSubscription (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 we are buying a group subscription
|
||||
if (data.groupId) {
|
||||
const groupFields = basicGroupFields.concat(' purchased');
|
||||
|
|
@ -299,6 +282,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,
|
||||
|
|
@ -315,24 +302,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue