mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 23:42:12 +00:00
Revert "fix(subscriptions): avoid parallelSave from recursive fn call"
This reverts commit ff93dd9159.
This commit is contained in:
parent
cb999d9277
commit
0e1011b875
7 changed files with 18 additions and 37 deletions
|
|
@ -18,7 +18,6 @@ import { // eslint-disable-line import/no-cycle
|
|||
} from '../../models/group';
|
||||
import { model as Coupon } from '../../models/coupon';
|
||||
import { getGemsBlock } from './gems'; // eslint-disable-line import/no-cycle
|
||||
import promoSubscription from './promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
|
||||
// TODO better handling of errors
|
||||
|
||||
|
|
@ -186,8 +185,6 @@ api.checkout = async function checkout (options = {}) {
|
|||
gift.member = await User.findById(gift.uuid).exec();
|
||||
data.gift = gift;
|
||||
data.paymentMethod = this.constants.PAYMENT_METHOD_GIFT;
|
||||
|
||||
promoSubscription(data);
|
||||
}
|
||||
|
||||
await payments[method](data);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import {
|
|||
} from '../errors';
|
||||
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
|
||||
import { model as User } from '../../models/user';
|
||||
import promoSubscription from './promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
|
||||
const api = {};
|
||||
|
||||
|
|
@ -237,8 +236,6 @@ api.noRenewSubscribe = async function noRenewSubscribe (options) {
|
|||
gift.subscription = sub;
|
||||
data.gift = gift;
|
||||
data.paymentMethod = this.constants.PAYMENT_METHOD_GIFT;
|
||||
|
||||
promoSubscription(data);
|
||||
}
|
||||
|
||||
await payments.createSubscription(data);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import {
|
|||
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
|
||||
import { model as User } from '../../models/user';
|
||||
import { getGemsBlock } from './gems';
|
||||
import promoSubscription from './promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
|
||||
const api = {};
|
||||
|
||||
|
|
@ -219,8 +218,6 @@ api.noRenewSubscribe = async function noRenewSubscribe (options) {
|
|||
gift.subscription = sub;
|
||||
data.gift = gift;
|
||||
data.paymentMethod = this.constants.PAYMENT_METHOD_GIFT;
|
||||
|
||||
promoSubscription(data);
|
||||
}
|
||||
|
||||
await payments.createSubscription(data);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import payments from './payments'; // eslint-disable-line import/no-cycle
|
|||
import { getGemsBlock } from './gems'; // eslint-disable-line import/no-cycle
|
||||
import { model as Coupon } from '../../models/coupon';
|
||||
import { model as User } from '../../models/user'; // eslint-disable-line import/no-cycle
|
||||
import promoSubscription from './promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
import { // eslint-disable-line import/no-cycle
|
||||
model as Group,
|
||||
basicFields as basicGroupFields,
|
||||
|
|
@ -163,8 +162,6 @@ api.checkoutSuccess = async function checkoutSuccess (options = {}) {
|
|||
|
||||
data.paymentMethod = 'PayPal (Gift)';
|
||||
data.gift = gift;
|
||||
|
||||
promoSubscription(data);
|
||||
} else {
|
||||
data.gemsBlock = getGemsBlock(gemsBlockKey);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
import { getCurrentEvent } from '../worldState'; // eslint-disable-line import/no-cycle
|
||||
import createSubscription from './payments'; // eslint-disable-line import/no-cycle
|
||||
|
||||
const currentEvent = getCurrentEvent();
|
||||
|
||||
export default async function promoSubscription (data) {
|
||||
if (currentEvent && currentEvent.promo && currentEvent.promo === 'g1g1') {
|
||||
const promoData = {
|
||||
user: data.user,
|
||||
gift: {
|
||||
member: data.user,
|
||||
subscription: {
|
||||
key: data.gift.subscription.key,
|
||||
},
|
||||
},
|
||||
paymentMethod: data.paymentMethod,
|
||||
promo: 'Winter',
|
||||
promoUsername: data.gift.member.auth.local.username,
|
||||
};
|
||||
await createSubscription(promoData);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,6 @@ import {
|
|||
import payments from '../payments'; // eslint-disable-line import/no-cycle
|
||||
import { getGemsBlock } from '../gems'; // eslint-disable-line import/no-cycle
|
||||
import stripeConstants from './constants';
|
||||
import promoSubscription from '../promoSubscription'; // eslint-disable-line import/no-cycle
|
||||
|
||||
function getGiftAmount (gift) {
|
||||
if (gift.type === 'subscription') {
|
||||
|
|
@ -99,8 +98,6 @@ async function applyGemPayment (user, response, gemsBlock, gift) {
|
|||
if (gift) {
|
||||
if (gift.type === 'subscription') method = 'createSubscription';
|
||||
data.paymentMethod = 'Gift';
|
||||
|
||||
promoSubscription(data);
|
||||
}
|
||||
|
||||
await payments[method](data);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {
|
|||
import shared from '../../../common';
|
||||
import { sendNotification as sendPushNotification } from '../pushNotifications'; // eslint-disable-line import/no-cycle
|
||||
import calculateSubscriptionTerminationDate from './calculateSubscriptionTerminationDate';
|
||||
import { getCurrentEvent } from '../worldState'; // eslint-disable-line import/no-cycle
|
||||
|
||||
// @TODO: Abstract to shared/constant
|
||||
const JOINED_GROUP_PLAN = 'joined group plan';
|
||||
|
|
@ -243,6 +244,23 @@ async function createSubscription (data) {
|
|||
|
||||
// Only send push notifications if sending to a user other than yourself
|
||||
if (data.gift.member._id !== data.user._id) {
|
||||
const currentEvent = getCurrentEvent();
|
||||
if (currentEvent && currentEvent.promo && currentEvent.promo === 'g1g1') {
|
||||
const promoData = {
|
||||
user: data.user,
|
||||
gift: {
|
||||
member: data.user,
|
||||
subscription: {
|
||||
key: data.gift.subscription.key,
|
||||
},
|
||||
},
|
||||
paymentMethod: data.paymentMethod,
|
||||
promo: 'Winter',
|
||||
promoUsername: data.gift.member.auth.local.username,
|
||||
};
|
||||
await this.createSubscription(promoData);
|
||||
}
|
||||
|
||||
if (data.gift.member.preferences.pushNotifications.giftedSubscription !== false) {
|
||||
sendPushNotification(data.gift.member,
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue