fix: Subscription active detarminer

This commit is contained in:
Ahmed Bouhuolia
2024-08-30 17:52:53 +02:00
parent ee2d8d3065
commit 410c4ea3e2
2 changed files with 10 additions and 9 deletions

View File

@@ -2,7 +2,6 @@ import { Container } from 'typedi';
import { Request, Response, NextFunction } from 'express'; import { Request, Response, NextFunction } from 'express';
const SupportedMethods = ['POST', 'PUT']; const SupportedMethods = ['POST', 'PUT'];
const Excluded = [];
export default (subscriptionSlug = 'main') => export default (subscriptionSlug = 'main') =>
async (req: Request, res: Response, next: NextFunction) => { async (req: Request, res: Response, next: NextFunction) => {
@@ -22,7 +21,10 @@ export default (subscriptionSlug = 'main') =>
errors: [{ type: 'TENANT.HAS.NO.SUBSCRIPTION' }], 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, { return res.boom.badRequest(null, {
errors: [{ type: 'ORGANIZATION.SUBSCRIPTION.INACTIVE' }], errors: [{ type: 'ORGANIZATION.SUBSCRIPTION.INACTIVE' }],
}); });

View File

@@ -136,14 +136,13 @@ export default class PlanSubscription extends mixin(SystemModel) {
/** /**
* Check if the subscription is active. * Check if the subscription is active.
* Crtiria should be: * Crtiria should be active:
* - During the trial period and NOT canceled. * - During the trial period should NOT be canceled.
* - Not ended. * - Out of trial period should NOT be ended.
*
* @return {Boolean} * @return {Boolean}
*/ */
public active() { public active() {
return this.onTrial() || !this.ended(); return this.onTrial() ? !this.canceled() : !this.ended();
} }
/** /**