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!

refactoring

kruzhambusbbd23b98fcbd
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index f7b916f0f..c1e267771 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -94,6 +94,28 @@ export class UserController {
}
}
+ @Post('/api-key')
+ @UseGuards(RolesGuard)
+ @UseGuards(SelfhostedGuard)
+ @Roles(UserType.CUSTOMER, UserType.ADMIN)
+ async generateApiKey(@CurrentUserId() userId: string): Promise<{
+ apiKey: string
+ }> {
+ this.logger.log({ userId }, 'POST /user/api-key')
+
+ const user = await this.userService.findOne(userId)
+
+ if (!_isNull(user.apiKey)) {
+ throw new ConflictException('You already have an API key')
+ }
+
+ const apiKey: string = uuidv4()
+
+ await this.userService.update(userId, { apiKey })
+
+ return { apiKey }
+ }
+
@Delete('/api-key')
@UseGuards(RolesGuard)
@UseGuards(SelfhostedGuard)
@@ -374,26 +396,4 @@ export class UserController {
return user
}
- @Post('/api-key')
- @UseGuards(RolesGuard)
- @UseGuards(SelfhostedGuard)
- @Roles(UserType.CUSTOMER, UserType.ADMIN)
- async generateApiKey(@CurrentUserId() userId: string): Promise<{
- apiKey: string
- }> {
- this.logger.log({ userId }, 'POST /user/api-key')
-
- const user = await this.userService.findOne(userId)
-
- if (!_isNull(user.apiKey)) {
- throw new ConflictException('You already have an API key')
- }
-
- const apiKey: string = uuidv4()
-
- await this.userService.update(userId, { apiKey })
-
- return { apiKey }
- }
-
}