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 checking if the user has an API key

Yevhenii K1fb88369f547
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index 571477d07..970993616 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -362,35 +362,31 @@ export class UserController {
@UseGuards(RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async generateApiKey(@CurrentUserId() userId: string): Promise<{
- generatedApiKey: string
+ apiKey: string;
}> {
- const apiKey = await this.userService.findOne(userId, {
- select: ['apiKey'],
- })
+ const user = await this.userService.findOne(userId);
- if (!_isNull(apiKey)) {
- throw new ConflictException('You already have an API key')
+ if (!_isNull(user.apiKey)) {
+ throw new ConflictException('You already have an API key');
}
- const generatedApiKey: string = uuidv4()
+ const apiKey: string = uuidv4();
- await this.userService.update(userId, { apiKey: generatedApiKey })
+ await this.userService.update(userId, { apiKey });
- return { generatedApiKey }
+ return { apiKey };
}
@Delete('api-key')
@UseGuards(RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async deleteApiKey(@CurrentUserId() userId: string): Promise<void> {
- const apiKey = await this.userService.findOne(userId, {
- select: ['apiKey'],
- })
+ const user = await this.userService.findOne(userId);
- if (_isNull(apiKey)) {
- throw new ConflictException("You don't have an API key")
+ if (_isNull(user.apiKey)) {
+ throw new ConflictException("You don't have an API key");
}
- await this.userService.update(userId, { apiKey: null })
+ await this.userService.update(userId, { apiKey: null });
}
}