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!

do not delete accounts with active subscriptions

Blue Mouse730adc075fa0
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index 456d78204..d5c8ce6bc 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -13,7 +13,7 @@ import * as _isEmpty from 'lodash/isEmpty'
import { UserService } from './user.service'
import { ProjectService } from '../project/project.service'
import {
- User, UserType, MAX_EMAIL_REQUESTS,
+ User, UserType, MAX_EMAIL_REQUESTS, PlanCode,
} from './entities/user.entity'
import { Roles } from '../common/decorators/roles.decorator'
import { Pagination } from '../common/pagination/pagination'
@@ -98,13 +98,17 @@ export class UserController {
this.logger.log({ id, uid }, 'DELETE /user/:id')
const user = await this.userService.findOne(id, {
relations: ['projects'],
- select: ['id'],
+ select: ['id', 'planCode'],
})
if (_isEmpty(user)) {
throw new BadRequestException(`User with id ${id} does not exist`)
}
+ if (user.planCode !== PlanCode.free) {
+ throw new BadRequestException('cancelSubFirst')
+ }
+
const pids = _join(_map(user.projects, el => `'${el.id}'`), ',')
const query1 = `ALTER table analytics DELETE WHERE pid IN (${pids})`
const query2 = `ALTER table customEV DELETE WHERE pid IN (${pids})`
@@ -114,11 +118,11 @@ export class UserController {
await clickhouse.query(query1).toPromise()
await clickhouse.query(query2).toPromise()
await this.userService.delete(id)
-
- return 'Account has been deleted'
+
+ return 'accountDeleted'
} catch(e) {
this.logger.error(e)
- return 'Error while deleting user account'
+ throw new BadRequestException('accountDeleteError')
}
}
@@ -132,9 +136,13 @@ export class UserController {
const user = await this.userService.findOne(id, {
relations: ['projects'],
- select: ['id'],
+ select: ['id', 'planCode'],
})
+ if (user.planCode !== PlanCode.free) {
+ throw new BadRequestException('cancelSubFirst')
+ }
+
try {
if (!_isEmpty(user.projects)) {
const pids = _join(_map(user.projects, el => `'${el.id}'`), ',')
@@ -145,11 +153,11 @@ export class UserController {
await clickhouse.query(query2).toPromise()
}
await this.userService.delete(id)
-
- return 'Account has been deleted'
+
+ return 'accountDeleted'
} catch(e) {
this.logger.error(e)
- return 'Error while deleting your account'
+ throw new BadRequestException('accountDeleteError')
}
}