Skip to content
Permalink
Browse files
FIX: Shouldn't send cancellation email if user has other active subsc…
…riptions.
  • Loading branch information
hijohnnylin committed Jun 26, 2019
1 parent 6c9e70c commit 85274894cc436ab067da72dfad5843e2226b3f34
Showing 1 changed file with 33 additions and 25 deletions.
@@ -302,39 +302,47 @@ class Subscription {
return User.getWithId(this.userId, "id, email, email_encrypted, email_confirmed")
.then(user => {
if (user.emailEncrypted && user.emailConfirmed == true) {
return Email.sendCancelSubscription(user.email)
.then( success => {
Logger.info("Cancellation email sent.");
return Database.query(
`UPDATE subscriptions
SET sent_cancellation_email = $1
WHERE receipt_id = $2
RETURNING *`,
[true, this.receiptId])
.catch( error => {
Logger.error("ERROR Couldn't set sent_cancellation_email for: " + this.receiptId, error);
})
.then(result => {
if (result.rowCount !== 1) {
Logger.error("ERROR Couldn't set sent_cancellation_email for: " + this.receiptId);
}
else {
Logger.info("Cancellation email sent flag set to true.");
return new Subscription(result.rows[0]);
}
});
});
return User.hasActiveSubscription(this.userId)
.then(hasActiveSubscription => {
if (hasActiveSubscription == true) {
Logger.info("Still has other active subscription, not sending cancellation email.")
return this;
}
else {
return Email.sendCancelSubscription(user.email)
.then( success => {
Logger.info("Cancellation email sent.");
return Database.query(
`UPDATE subscriptions
SET sent_cancellation_email = $1
WHERE receipt_id = $2
RETURNING *`,
[true, this.receiptId])
.catch( error => {
Logger.error("ERROR Couldn't set sent_cancellation_email for: " + this.receiptId, error);
})
.then(result => {
if (result.rowCount !== 1) {
Logger.error("ERROR Couldn't set sent_cancellation_email for: " + this.receiptId);
}
else {
Logger.info("Cancellation email sent flag set to true.");
return new Subscription(result.rows[0]);
}
});
});
}
})
}
else {
// No user email, no email to send
Logger.info("No user email, not sending cancellation email.")
return true;
return this;
}
})
}
else {
Logger.info("Not sending cancellation email, already sent.");
return true;
return this;
}
}

0 comments on commit 8527489

Please sign in to comment.