mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix: Subscription active detarminer
This commit is contained in:
@@ -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' }],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user