Skip to content

Commit

Permalink
fix: Subscription active detarminer
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Aug 30, 2024
1 parent ee2d8d3 commit 410c4ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/server/src/api/middleware/SubscriptionMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Container } from 'typedi';
import { Request, Response, NextFunction } from 'express';

const SupportedMethods = ['POST', 'PUT'];
const Excluded = [];

export default (subscriptionSlug = 'main') =>
async (req: Request, res: Response, next: NextFunction) => {
Expand All @@ -22,7 +21,10 @@ export default (subscriptionSlug = 'main') =>
errors: [{ type: 'TENANT.HAS.NO.SUBSCRIPTION' }],
});
}
if (SupportedMethods.includes(req.method) && subscription.inactive()) {
const isMethodSupported = SupportedMethods.includes(req.method);
const isSubscriptionInactive = subscription.inactive();

if (isMethodSupported && isSubscriptionInactive) {
return res.boom.badRequest(null, {
errors: [{ type: 'ORGANIZATION.SUBSCRIPTION.INACTIVE' }],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ export default class PlanSubscription extends mixin(SystemModel) {

/**
* Filter the failed payment.
* @param builder
* @param builder
*/
failedPayment(builder) {
builder.where('payment_status', SubscriptionPaymentStatus.Failed);
},

/**
* Filter the succeed payment.
* @param builder
* @param builder
*/
succeedPayment(builder) {
builder.where('payment_status', SubscriptionPaymentStatus.Succeed);
Expand Down Expand Up @@ -136,14 +136,13 @@ export default class PlanSubscription extends mixin(SystemModel) {

/**
* Check if the subscription is active.
* Crtiria should be:
* - During the trial period and NOT canceled.
* - Not ended.
*
* Crtiria should be active:
* - During the trial period should NOT be canceled.
* - Out of trial period should NOT be ended.
* @return {Boolean}
*/
public active() {
return this.onTrial() || !this.ended();
return this.onTrial() ? !this.canceled() : !this.ended();
}

/**
Expand Down

0 comments on commit 410c4ea

Please sign in to comment.