Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(improvement) Move maxprojects to user table #194

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -85,7 +85,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 @@ -243,15 +243,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 @@ -297,7 +297,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 @@ -316,7 +316,7 @@ export class ProjectController {
_filter(
user.projects,
(project: Project) => project.isCaptchaProject,
) >= (maxProjects || PROJECTS_MAXIMUM),
) >= maxProjects,
)
) {
throw new HttpException(
Expand All @@ -329,7 +329,7 @@ export class ProjectController {
_filter(
user.projects,
(project: Project) => project.isAnalyticsProject,
) >= (maxProjects || PROJECTS_MAXIMUM),
) >= maxProjects,
)
) {
throw new ForbiddenException(
Expand Down Expand Up @@ -1236,9 +1236,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';