Skip to content

Commit

Permalink
Fix: suggested plancode is [object Object]
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaumaus committed Aug 26, 2024
1 parent 4b9ae52 commit f4cf089
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions apps/production/src/task-manager/task-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class TaskManagerService {
hitPercentageLimit: _includes(exceedingUserIds, user.id),
percentageLimit: TRAFFIC_SPIKE_ALLOWED_PERCENTAGE * 100,
billingUrl: 'https://swetrix.com/billing',
suggestedPlanLimit,
suggestedPlanLimit: suggestedPlanLimit?.monthlyUsageLimit,
}

await this.mailerService.sendEmail(
Expand Down Expand Up @@ -525,7 +525,7 @@ export class TaskManagerService {
thisMonthUsage: usage,
percentageLimit: TRAFFIC_SPIKE_ALLOWED_PERCENTAGE * 100,
billingUrl: 'https://swetrix.com/billing',
suggestedPlanLimit,
suggestedPlanLimit: suggestedPlanLimit?.monthlyUsageLimit,
}

await this.mailerService.sendEmail(
Expand Down Expand Up @@ -592,7 +592,7 @@ export class TaskManagerService {
lastMonthUsage: userLastMonthUsage,
percentageLimit: TRAFFIC_SPIKE_ALLOWED_PERCENTAGE * 100,
billingUrl: 'https://swetrix.com/billing',
suggestedPlanLimit,
suggestedPlanLimit: suggestedPlanLimit?.monthlyUsageLimit,
}

await this.mailerService.sendEmail(
Expand Down
31 changes: 22 additions & 9 deletions apps/production/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export enum DashboardBlockReason {
'subscription_cancelled' = 'subscription_cancelled',
}

interface PlanSignature {
id: PlanCode
monthlyUsageLimit: number
maxAlerts: number
legacy: boolean
pid?: string
ypid?: string
}

export const ACCOUNT_PLANS = {
[PlanCode.none]: {
id: PlanCode.none,
Expand Down Expand Up @@ -123,19 +132,23 @@ export const ACCOUNT_PLANS = {
},
}

export const getNextPlan = (planCode: PlanCode) => {
export const getNextPlan = (planCode: PlanCode): PlanSignature | undefined => {
const currentLimit = ACCOUNT_PLANS[planCode].monthlyUsageLimit

let nextPlan

Object.values(ACCOUNT_PLANS).some(plan => {
if (plan.monthlyUsageLimit > currentLimit) {
nextPlan = plan
return true
}

return false
})
Object.values(ACCOUNT_PLANS)
.filter(
plan => ![PlanCode.free, PlanCode.trial, PlanCode.none].includes(plan.id),
)
.some(plan => {
if (plan.monthlyUsageLimit > currentLimit) {
nextPlan = plan
return true
}

return false
})

return nextPlan
}
Expand Down

0 comments on commit f4cf089

Please sign in to comment.