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!

some fixes & improvements

Blue Mouseda688483b187
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index bcb12c842..b5ac085f9 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -396,6 +396,27 @@ export class UserController {
}
}
+ @Delete('/tg/:id')
+ @UseGuards(RolesGuard)
+ @UseGuards(SelfhostedGuard)
+ @Roles(UserType.CUSTOMER, UserType.ADMIN)
+ @HttpCode(204)
+ async deleteTelegramConnection(
+ @Param('id') tgID: string,
+ @CurrentUserId() id: string,
+ ): Promise<any> {
+ this.logger.log({ tgID, id }, 'DELETE /user/tg/:id')
+
+ const user = await this.userService.findOneWhere({ id })
+
+ if (tgID && user.telegramChatId === tgID) {
+ await this.userService.update(id, {
+ telegramChatId: null,
+ isTelegramChatIdConfirmed: false,
+ })
+ }
+ }
+
@Put('/')
@UseGuards(RolesGuard)
@UseGuards(SelfhostedGuard)
@@ -450,10 +471,14 @@ export class UserController {
if (userWithByTelegramChatId) {
throw new BadRequestException(
- 'User with this telegram chat id already exists',
+ 'User with this Telegram chat ID already exists',
)
}
+ await this.userService.update(id, {
+ isTelegramChatIdConfirmed: false,
+ })
+
this.bot.telegram.sendMessage(
userDTO.telegramChatId,
'Confirm the connection between your Telegram account and your Swetrix account.',
@@ -498,11 +523,9 @@ export class UserController {
'twoFactorRecoveryCode',
'twoFactorAuthenticationSecret',
'isTwoFactorAuthenticationEnabled',
+ 'isTelegramChatIdConfirmed',
])
- await this.userService.update(id, {
- ...userToUpdate,
- isTelegramChatIdConfirmed: false,
- })
+ await this.userService.update(id, userToUpdate)
const updatedUser = await this.userService.findOneWhere({ id })
return this.userService.omitSensitiveData(updatedUser)