Skip to content

📈 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!

fixed broken count

Blue Mouseefa5e4c2d71e
diff --git a/src/alert/alert.controller.ts b/src/alert/alert.controller.ts
index a65ead066..1cae59bd2 100644
--- a/src/alert/alert.controller.ts
+++ b/src/alert/alert.controller.ts
@@ -9,7 +9,6 @@ import { RolesGuard } from '../common/guards/roles.guard'
import * as _isEmpty from 'lodash/isEmpty'
import * as _map from 'lodash/map'
import * as _omit from 'lodash/omit'
-import * as _size from 'lodash/size'
import { UserService } from 'src/user/user.service'
import { ProjectService } from 'src/project/project.service'
@@ -77,12 +76,6 @@ export class AlertController {
throw new ForbiddenException('Please, verify your email address first')
}
- if (_size(user.projects) >= (maxAlerts || ALERTS_MAXIMUM)) {
- throw new ForbiddenException(
- `You cannot create more than ${maxAlerts} alerts on your account plan. Please upgrade to be able to create more alerts.`,
- )
- }
-
const project = await this.projectService.findOneWhere({
id: alertDTO.pid,
}, {
@@ -95,6 +88,15 @@ export class AlertController {
this.projectService.allowedToManage(project, uid, user.roles, 'You are not allowed to manage this project')
+ const pids = _map(user.projects, (project) => project.id)
+ const alertsCount = await this.alertService.count({ project: In(pids) })
+
+ if (alertsCount >= (maxAlerts || ALERTS_MAXIMUM)) {
+ throw new ForbiddenException(
+ `You cannot create more than ${maxAlerts} alerts on your account plan. Please upgrade to be able to create more alerts.`,
+ )
+ }
+
try {
let alert = new Alert()
Object.assign(alert, alertDTO)
diff --git a/src/alert/alert.service.ts b/src/alert/alert.service.ts
index 9c3015c14..8042c3c63 100644
--- a/src/alert/alert.service.ts
+++ b/src/alert/alert.service.ts
@@ -39,6 +39,10 @@ export class AlertService {
return this.alertsReporsitory.findOne(id, { relations: ['project'] })
}
+ async count(options: object = {}): Promise<number> {
+ return await this.alertsReporsitory.count(options)
+ }
+
findOne(id: string, params: Object = {}): Promise<Alert | null> {
return this.alertsReporsitory.findOne(id, params)
}