Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat(subscription): re-enable disabled channels when the new plan can hold all of them

Gilad Resisi4a6ba07f88e5
diff --git a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
index 37274a6f3..48a33277e 100644
--- a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
@@ -842,6 +842,30 @@ export class IntegrationRepository {
}
}
+ async enableAllIntegrations(org: string) {
+ const getChannels = await this._integration.model.integration.findMany({
+ where: {
+ organizationId: org,
+ disabled: true,
+ deletedAt: null,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ for (const channel of getChannels) {
+ await this._integration.model.integration.update({
+ where: {
+ id: channel.id,
+ },
+ data: {
+ disabled: false,
+ },
+ });
+ }
+ }
+
getPlugsByIntegrationId(org: string, id: string) {
return this._plugs.model.plugs.findMany({
where: {
diff --git a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts
index 6a226355b..003450309 100644
--- a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts
@@ -394,6 +394,10 @@ export class IntegrationService {
return this._integrationRepository.disableIntegrations(org, totalChannels);
}
+ async enableAllIntegrations(org: string) {
+ return this._integrationRepository.enableAllIntegrations(org);
+ }
+
async checkForDeletedOnceAndUpdate(org: string, page: string) {
return this._integrationRepository.checkForDeletedOnceAndUpdate(org, page);
}
diff --git a/libraries/nestjs-libraries/src/database/prisma/subscriptions/subscription.service.ts b/libraries/nestjs-libraries/src/database/prisma/subscriptions/subscription.service.ts
index 9c727f71f..e7e749e04 100644
--- a/libraries/nestjs-libraries/src/database/prisma/subscriptions/subscription.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/subscriptions/subscription.service.ts
@@ -108,9 +108,10 @@ export class SubscriptionService {
const from = pricing[getCurrentSubscription?.subscriptionTier || 'FREE'];
const to = pricing[billing];
- const currentTotalChannels = (
- await this._integrationService.getIntegrationsList(organizationId)
- ).filter((f) => !f.disabled);
+ const allChannels = await this._integrationService.getIntegrationsList(
+ organizationId
+ );
+ const currentTotalChannels = allChannels.filter((f) => !f.disabled);
if (currentTotalChannels.length > totalChannels) {
await this._integrationService.disableIntegrations(
@@ -119,6 +120,17 @@ export class SubscriptionService {
);
}
+ // channels are auto-disabled when a subscription lapses; once the new plan
+ // can hold all of them, enable everything back (partial enabling would risk
+ // enabling channels the user disabled on purpose)
+ if (
+ billing !== 'FREE' &&
+ currentTotalChannels.length < allChannels.length &&
+ allChannels.length <= totalChannels
+ ) {
+ await this._integrationService.enableAllIntegrations(organizationId);
+ }
+
if (from.team_members && !to.team_members) {
await this._organizationService.disableOrEnableNonSuperAdminUsers(
organizationId,
@@ -169,11 +181,10 @@ export class SubscriptionService {
const from = pricing[getCurrentSubscription?.subscriptionTier || 'FREE'];
const to = pricing[billing];
- const currentTotalChannels = (
- await this._integrationService.getIntegrationsList(
- getOrgByCustomerId?.id!
- )
- ).filter((f) => !f.disabled);
+ const allChannels = await this._integrationService.getIntegrationsList(
+ getOrgByCustomerId?.id!
+ );
+ const currentTotalChannels = allChannels.filter((f) => !f.disabled);
if (currentTotalChannels.length > totalChannels) {
await this._integrationService.disableIntegrations(
@@ -182,6 +193,19 @@ export class SubscriptionService {
);
}
+ // channels are auto-disabled when a subscription lapses; once the new plan
+ // can hold all of them, enable everything back (partial enabling would risk
+ // enabling channels the user disabled on purpose)
+ if (
+ billing !== 'FREE' &&
+ currentTotalChannels.length < allChannels.length &&
+ allChannels.length <= totalChannels
+ ) {
+ await this._integrationService.enableAllIntegrations(
+ getOrgByCustomerId?.id!
+ );
+ }
+
if (from.team_members && !to.team_members) {
await this._organizationService.disableOrEnableNonSuperAdminUsers(
getOrgByCustomerId?.id!,