📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Add new library for request retries, and update PUT endoint to handle webhook updates with DTO
Yehor Dremliuha667b05c4da4d
diff --git a/apps/production/src/user/user.controller.ts b/apps/production/src/user/user.controller.tsindex 3f037ee5d..12febedb1 100644--- a/apps/production/src/user/user.controller.ts+++ b/apps/production/src/user/user.controller.ts@@ -31,6 +31,8 @@ import * as _isString from 'lodash/isString'import * as _omit from 'lodash/omit'import * as _round from 'lodash/round'import { v4 as uuidv4 } from 'uuid'+import { HttpService } from '@nestjs/axios'+import { firstValueFrom, map } from 'rxjs'import { Markup } from 'telegraf'import { JwtAccessTokenGuard } from '../auth/guards'@@ -91,6 +93,7 @@ export class UserController {private readonly mailerService: MailerService,private readonly logger: AppLoggerService,private readonly telegramService: TelegramService,+ private readonly httpService: HttpService,) {}@ApiBearerAuth()@@ -639,6 +642,46 @@ export class UserController {)}+ if (userDTO.slackWebhookUrl) {+ const slackWebhookResponse = await firstValueFrom(+ this.httpService+ .get<string>(userDTO.discordWebhookUrl)+ .pipe(map(response => response.data)),+ )++ if (slackWebhookResponse === 'invalid_token') {+ throw new ConflictException('Invalid Slack URL.')+ }++ await this.userService.update(id, {+ slackWebhookUrl: userDTO.slackWebhookUrl,+ })+ } else if (userDTO.slackWebhookUrl === null) {+ await this.userService.update(id, {+ slackWebhookUrl: null,+ })+ }++ if (userDTO.discordWebhookUrl) {+ const discordWebhookResponse = await firstValueFrom(+ this.httpService+ .get<{ code?: number }>(userDTO.discordWebhookUrl)+ .pipe(map(response => response.data)),+ )++ if (discordWebhookResponse.code === 50027) {+ throw new ConflictException('Invalid Discord URL.')+ }++ await this.userService.update(id, {+ discordWebhookUrl: userDTO.discordWebhookUrl,+ })+ } else if (userDTO.discordWebhookUrl === null) {+ await this.userService.update(id, {+ discordWebhookUrl: null,+ })+ }+if (userDTO.timeFormat && user.timeFormat !== userDTO.timeFormat) {await this.userService.update(id, {timeFormat: userDTO.timeFormat,diff --git a/apps/production/src/user/user.module.ts b/apps/production/src/user/user.module.tsindex 2d99b822b..b7bbd6967 100644--- a/apps/production/src/user/user.module.ts+++ b/apps/production/src/user/user.module.ts@@ -1,5 +1,6 @@import { Module, forwardRef } from '@nestjs/common'import { TypeOrmModule } from '@nestjs/typeorm'+import { HttpModule } from '@nestjs/axios'import { TelegramService } from '../integrations/telegram/telegram.service'import { UserController } from './user.controller'@@ -24,6 +25,7 @@ import { Message } from '../integrations/telegram/entities/message.entity'AppLoggerModule,ProjectModule,PayoutsModule,+ HttpModule,],providers: [UserService, TelegramService],exports: [UserService],diff --git a/package.json b/package.jsonindex 0105643d5..a6eafee7c 100644--- a/package.json+++ b/package.json@@ -45,7 +45,7 @@"@sentry/cli": "^2.32.1","@sentry/nestjs": "^8.13.0","@sentry/profiling-node": "^8.13.0",- "axios": "^1.6.8",+ "axios": "^1.7.2","bcrypt": "^5.1.1","blake3": "^2.1.7","body-parser": "^1.20.2",