Skip to content

Commit

Permalink
moved maxprojects to user table (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaumaus authored Oct 6, 2023
1 parent 05dc675 commit 3e1049f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
16 changes: 8 additions & 8 deletions apps/production/src/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import {
ShareUpdateDTO,
} from './dto'

const PROJECTS_MAXIMUM = ACCOUNT_PLANS[PlanCode.free].maxProjects
const PROJECTS_MAXIMUM = 50

const isValidShareDTO = (share: ShareDTO): boolean => {
return !_isEmpty(_trim(share.email)) && _includes(roles, share.role)
Expand Down Expand Up @@ -288,15 +288,15 @@ export class ProjectController {
const user = await this.userService.findOneWithRelations(userId, [
'projects',
])
const maxProjects = ACCOUNT_PLANS[user.planCode]?.maxProjects
const { maxProjects = PROJECTS_MAXIMUM } = user

if (!user.isActive) {
throw new ForbiddenException(
"User's email address has to be verified first",
)
}

if (_size(user.projects) >= (maxProjects || PROJECTS_MAXIMUM)) {
if (_size(user.projects) >= maxProjects) {
throw new ForbiddenException(
`The user's plan supports maximum of ${maxProjects} projects`,
)
Expand Down Expand Up @@ -342,7 +342,7 @@ export class ProjectController {
const user = await this.userService.findOneWithRelations(userId, [
'projects',
])
const maxProjects = ACCOUNT_PLANS[user.planCode]?.maxProjects
const { maxProjects = PROJECTS_MAXIMUM } = user

if (!user.isActive) {
throw new ForbiddenException('Please, verify your email address first')
Expand All @@ -361,7 +361,7 @@ export class ProjectController {
_filter(
user.projects,
(project: Project) => project.isCaptchaProject,
) >= (maxProjects || PROJECTS_MAXIMUM),
) >= maxProjects,
)
) {
throw new HttpException(
Expand All @@ -374,7 +374,7 @@ export class ProjectController {
_filter(
user.projects,
(project: Project) => project.isAnalyticsProject,
) >= (maxProjects || PROJECTS_MAXIMUM),
) >= maxProjects,
)
) {
throw new ForbiddenException(
Expand Down Expand Up @@ -1281,9 +1281,9 @@ export class ProjectController {
user.projects,
(fProject: Project) => fProject.isCaptchaProject,
)
const maxProjects = ACCOUNT_PLANS[user.planCode]?.maxProjects
const { maxProjects = PROJECTS_MAXIMUM } = user

if (_size(captchaProjects >= (maxProjects || PROJECTS_MAXIMUM))) {
if (_size(captchaProjects >= maxProjects)) {
throw new ForbiddenException(
`You cannot create more than ${maxProjects} projects on your account plan. Please upgrade to be able to create more projects.`,
)
Expand Down
25 changes: 3 additions & 22 deletions apps/production/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,28 @@ export enum PlanCode {
export const ACCOUNT_PLANS = {
[PlanCode.none]: {
id: PlanCode.none,
displayName: 'No plan',
monthlyUsageLimit: 0,
maxProjects: 0,
maxAlerts: 0,
maxApiKeyRequestsPerHour: 0,
legacy: false,
},
[PlanCode.free]: {
id: PlanCode.free,
displayName: 'Free plan',
monthlyUsageLimit: 5000,
maxProjects: 50,
maxAlerts: 1,
maxApiKeyRequestsPerHour: 600,
legacy: true,
},
[PlanCode.trial]: {
id: PlanCode.trial,
displayName: 'Free trial',
monthlyUsageLimit: 100000,
maxProjects: 50,
maxAlerts: 50,
maxApiKeyRequestsPerHour: 600,
legacy: false,
},
[PlanCode.hobby]: {
id: PlanCode.hobby,
displayName: 'Hobby plan',
monthlyUsageLimit: 10000,
maxProjects: 50,
pid: '813694', // Plan ID
ypid: '813695', // Plan ID - Yearly billing
maxAlerts: 50,
Expand All @@ -71,9 +63,7 @@ export const ACCOUNT_PLANS = {
},
[PlanCode.freelancer]: {
id: PlanCode.freelancer,
displayName: 'Freelancer plan',
monthlyUsageLimit: 100000,
maxProjects: 50,
pid: '752316', // Plan ID
ypid: '776469', // Plan ID - Yearly billing
maxAlerts: 50,
Expand All @@ -82,9 +72,7 @@ export const ACCOUNT_PLANS = {
},
[PlanCode['200k']]: {
id: PlanCode['200k'],
displayName: '200k events',
monthlyUsageLimit: 200000,
maxProjects: 50,
pid: '854654', // Plan ID
ypid: '854655', // Plan ID - Yearly billing
maxAlerts: 50,
Expand All @@ -93,9 +81,7 @@ export const ACCOUNT_PLANS = {
},
[PlanCode['500k']]: {
id: PlanCode['500k'],
displayName: '500k events',
monthlyUsageLimit: 500000,
maxProjects: 50,
pid: '854656', // Plan ID
ypid: '854657', // Plan ID - Yearly billing
maxAlerts: 50,
Expand All @@ -104,9 +90,7 @@ export const ACCOUNT_PLANS = {
},
[PlanCode.startup]: {
id: PlanCode.startup,
displayName: 'Startup plan',
monthlyUsageLimit: 1000000,
maxProjects: 50,
pid: '752317',
ypid: '776470',
maxAlerts: 50,
Expand All @@ -115,9 +99,7 @@ export const ACCOUNT_PLANS = {
},
[PlanCode['2m']]: {
id: PlanCode['2m'],
displayName: '2m events',
monthlyUsageLimit: 2000000,
maxProjects: 50,
pid: '854663', // Plan ID
ypid: '854664', // Plan ID - Yearly billing
maxAlerts: 50,
Expand All @@ -126,9 +108,7 @@ export const ACCOUNT_PLANS = {
},
[PlanCode.enterprise]: {
id: PlanCode.enterprise,
displayName: 'Enterprise plan',
monthlyUsageLimit: 5000000,
maxProjects: 50,
pid: '752318',
ypid: '776471',
maxAlerts: 50,
Expand All @@ -137,9 +117,7 @@ export const ACCOUNT_PLANS = {
},
[PlanCode['10m']]: {
id: PlanCode['10m'],
displayName: '10m events',
monthlyUsageLimit: 10000000,
maxProjects: 50,
pid: '854665', // Plan ID
ypid: '854666', // Plan ID - Yearly billing
maxAlerts: 50,
Expand Down Expand Up @@ -259,6 +237,9 @@ export class User {
@Column('varchar', { length: 50, default: Theme.classic })
theme: Theme

@Column('int', { default: 50 })
maxProjects: number

@Column({ default: false })
isTwoFactorAuthenticationEnabled: boolean

Expand Down
1 change: 1 addition & 0 deletions migrations/mysql/2023_10_06.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table user add column `maxProjects` int NOT NULL DEFAULT '50';

0 comments on commit 3e1049f

Please sign in to comment.