📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
moved maxprojects to user table (#194)
Andrii Romasiun3e1049f9aeb9
diff --git a/apps/production/src/project/project.controller.ts b/apps/production/src/project/project.controller.tsindex 6f4e268b2..d550f3577 100644--- a/apps/production/src/project/project.controller.ts+++ b/apps/production/src/project/project.controller.ts@@ -86,7 +86,7 @@ import {ShareUpdateDTO,} from './dto'-const PROJECTS_MAXIMUM = ACCOUNT_PLANS[PlanCode.free].maxProjects+const PROJECTS_MAXIMUM = 50const isValidShareDTO = (share: ShareDTO): boolean => {return !_isEmpty(_trim(share.email)) && _includes(roles, share.role)@@ -288,7 +288,7 @@ export class ProjectController {const user = await this.userService.findOneWithRelations(userId, ['projects',])- const maxProjects = ACCOUNT_PLANS[user.planCode]?.maxProjects+ const { maxProjects = PROJECTS_MAXIMUM } = userif (!user.isActive) {throw new ForbiddenException(@@ -296,7 +296,7 @@ export class ProjectController {)}- if (_size(user.projects) >= (maxProjects || PROJECTS_MAXIMUM)) {+ if (_size(user.projects) >= maxProjects) {throw new ForbiddenException(`The user's plan supports maximum of ${maxProjects} projects`,)@@ -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 } = userif (!user.isActive) {throw new ForbiddenException('Please, verify your email address first')@@ -361,7 +361,7 @@ export class ProjectController {_filter(user.projects,(project: Project) => project.isCaptchaProject,- ) >= (maxProjects || PROJECTS_MAXIMUM),+ ) >= maxProjects,)) {throw new HttpException(@@ -374,7 +374,7 @@ export class ProjectController {_filter(user.projects,(project: Project) => project.isAnalyticsProject,- ) >= (maxProjects || PROJECTS_MAXIMUM),+ ) >= maxProjects,)) {throw new ForbiddenException(@@ -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.`,)diff --git a/apps/production/src/user/entities/user.entity.ts b/apps/production/src/user/entities/user.entity.tsindex 236518b50..43b9d288f 100644--- a/apps/production/src/user/entities/user.entity.ts+++ b/apps/production/src/user/entities/user.entity.ts@@ -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 IDypid: '813695', // Plan ID - Yearly billingmaxAlerts: 50,@@ -71,9 +63,7 @@ export const ACCOUNT_PLANS = {},[PlanCode.freelancer]: {id: PlanCode.freelancer,- displayName: 'Freelancer plan',monthlyUsageLimit: 100000,- maxProjects: 50,pid: '752316', // Plan IDypid: '776469', // Plan ID - Yearly billingmaxAlerts: 50,@@ -82,9 +72,7 @@ export const ACCOUNT_PLANS = {},[PlanCode['200k']]: {id: PlanCode['200k'],- displayName: '200k events',monthlyUsageLimit: 200000,- maxProjects: 50,pid: '854654', // Plan IDypid: '854655', // Plan ID - Yearly billingmaxAlerts: 50,@@ -93,9 +81,7 @@ export const ACCOUNT_PLANS = {},[PlanCode['500k']]: {id: PlanCode['500k'],- displayName: '500k events',monthlyUsageLimit: 500000,- maxProjects: 50,pid: '854656', // Plan IDypid: '854657', // Plan ID - Yearly billingmaxAlerts: 50,@@ -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,@@ -115,9 +99,7 @@ export const ACCOUNT_PLANS = {},[PlanCode['2m']]: {id: PlanCode['2m'],- displayName: '2m events',monthlyUsageLimit: 2000000,- maxProjects: 50,pid: '854663', // Plan IDypid: '854664', // Plan ID - Yearly billingmaxAlerts: 50,@@ -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,@@ -137,9 +117,7 @@ export const ACCOUNT_PLANS = {},[PlanCode['10m']]: {id: PlanCode['10m'],- displayName: '10m events',monthlyUsageLimit: 10000000,- maxProjects: 50,pid: '854665', // Plan IDypid: '854666', // Plan ID - Yearly billingmaxAlerts: 50,@@ -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: booleandiff --git a/migrations/mysql/2023_10_06.sql b/migrations/mysql/2023_10_06.sqlnew file mode 100644index 000000000..b61c2aa76--- /dev/null+++ b/migrations/mysql/2023_10_06.sql@@ -0,0 +1 @@+alter table user add column `maxProjects` int NOT NULL DEFAULT '50';