From 7cb6d028cf6a7071c513d298ee7903deb9c34956 Mon Sep 17 00:00:00 2001 From: Roba Boru Date: Tue, 14 Jul 2026 10:46:27 +0300 Subject: [PATCH] Remove rate time --- apps/edr-passenger-api/src/app.module.ts | 11 +--- .../src/common/dynamic-throttler.guard.ts | 57 ------------------- .../src/modules/auth/auth.controller.ts | 1 - .../modules/bookings/bookings.controller.ts | 1 - .../src/modules/health/health.controller.ts | 2 - .../passengers/passengers.controller.ts | 1 - .../payments/internal-payments.controller.ts | 2 - .../modules/payments/payments.controller.ts | 1 - .../system-config/system-config.controller.ts | 2 - .../modules/verifayda/verifayda.controller.ts | 1 - .../src/modules/wallet/wallet.controller.ts | 1 - 11 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 apps/edr-passenger-api/src/common/dynamic-throttler.guard.ts diff --git a/apps/edr-passenger-api/src/app.module.ts b/apps/edr-passenger-api/src/app.module.ts index 6867acb6c..cce0f5e7d 100644 --- a/apps/edr-passenger-api/src/app.module.ts +++ b/apps/edr-passenger-api/src/app.module.ts @@ -1,7 +1,5 @@ import { Logger, Module, OnApplicationBootstrap } from "@nestjs/common"; -import { ThrottlerModule } from "@nestjs/throttler"; -import { DynamicThrottlerGuard } from "./common/dynamic-throttler.guard"; -import { APP_GUARD, APP_FILTER } from "@nestjs/core"; +import { APP_FILTER } from "@nestjs/core"; import { ConfigModule, ConfigService } from "@nestjs/config"; import { ScheduleModule } from "@nestjs/schedule"; import { EventEmitterModule } from "@nestjs/event-emitter"; @@ -69,11 +67,6 @@ import { EOtpType } from "@tria-plc/iamapi-common"; @Module({ imports: [ - // ThrottlerModule.forRoot([ - // { name: "auth", ttl: 60, limit: 100000 }, - // { name: "strict", ttl: 60, limit: 100000 }, - // { name: "default", ttl: 60, limit: 100000 }, - // ]), ConfigModule.forRoot({ isGlobal: true, load: [ @@ -149,9 +142,7 @@ import { EOtpType } from "@tria-plc/iamapi-common"; ConfigurableFareModule, ], providers: [ - { provide: APP_GUARD, useClass: DynamicThrottlerGuard }, { provide: APP_FILTER, useClass: DeleteExceptionFilter }, - DynamicThrottlerGuard, EdrPassengerOrgSeeder, PassengerStaffUsersSeeder, SegmentFareSeeder, diff --git a/apps/edr-passenger-api/src/common/dynamic-throttler.guard.ts b/apps/edr-passenger-api/src/common/dynamic-throttler.guard.ts deleted file mode 100644 index 5ad8232ec..000000000 --- a/apps/edr-passenger-api/src/common/dynamic-throttler.guard.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Injectable, ExecutionContext, Inject } from '@nestjs/common'; -import { Reflector } from '@nestjs/core'; -import { ThrottlerGuard, ThrottlerStorage, getOptionsToken, getStorageToken } from '@nestjs/throttler'; -import { SystemConfigService, CONFIG_KEYS } from '../modules/system-config/system-config.service'; - -// Route-prefix → throttler tier mapping. -// Evaluated in order; first match wins. -const ROUTE_TIERS: Array<{ prefix: string; tier: 'auth' | 'strict' | 'default' }> = [ - { prefix: '/auth', tier: 'auth' }, - { prefix: '/fayda/verification',tier: 'auth' }, - { prefix: '/bookings', tier: 'strict' }, - { prefix: '/passengers', tier: 'strict' }, - { prefix: '/payments', tier: 'strict' }, - { prefix: '/wallet', tier: 'strict' }, -]; - -@Injectable() -export class DynamicThrottlerGuard extends ThrottlerGuard { - constructor( - @Inject(getOptionsToken()) options: any, - @Inject(getStorageToken()) storageService: ThrottlerStorage, - reflector: Reflector, - private readonly systemConfig: SystemConfigService, - ) { - super(options, storageService, reflector); - } - - async canActivate(context: ExecutionContext): Promise { - if (context.getType() !== 'http') { - return true; - } - - const [authLimit, authTtl, strictLimit, strictTtl, defaultLimit, defaultTtl] = - await Promise.all([ - this.systemConfig.getNumber(CONFIG_KEYS.THROTTLE_AUTH_LIMIT), - this.systemConfig.getNumber(CONFIG_KEYS.THROTTLE_AUTH_TTL_MS), - this.systemConfig.getNumber(CONFIG_KEYS.THROTTLE_STRICT_LIMIT), - this.systemConfig.getNumber(CONFIG_KEYS.THROTTLE_STRICT_TTL_MS), - this.systemConfig.getNumber(CONFIG_KEYS.THROTTLE_DEFAULT_LIMIT), - this.systemConfig.getNumber(CONFIG_KEYS.THROTTLE_DEFAULT_TTL_MS), - ]); - - const url: string = context.switchToHttp().getRequest<{ url: string }>().url ?? ''; - const matched = ROUTE_TIERS.find(({ prefix }) => url.startsWith(prefix)); - const tier = matched?.tier ?? 'default'; - - if (tier === 'auth') { - this.throttlers = [{ name: 'auth', ttl: authTtl, limit: authLimit }]; - } else if (tier === 'strict') { - this.throttlers = [{ name: 'strict', ttl: strictTtl, limit: strictLimit }]; - } else { - this.throttlers = [{ name: 'default', ttl: defaultTtl, limit: defaultLimit }]; - } - - return super.canActivate(context); - } -} diff --git a/apps/edr-passenger-api/src/modules/auth/auth.controller.ts b/apps/edr-passenger-api/src/modules/auth/auth.controller.ts index 7f180137e..96ad8a178 100644 --- a/apps/edr-passenger-api/src/modules/auth/auth.controller.ts +++ b/apps/edr-passenger-api/src/modules/auth/auth.controller.ts @@ -20,7 +20,6 @@ import { ApiBody, ApiBearerAuth, } from "@nestjs/swagger"; -import { Throttle, SkipThrottle } from "@nestjs/throttler"; import { IsPublic } from "@tria-plc/api-common/modules/auth/decorators/public.decorator"; import { PassengerAuthService } from "./passenger-auth.service"; import { diff --git a/apps/edr-passenger-api/src/modules/bookings/bookings.controller.ts b/apps/edr-passenger-api/src/modules/bookings/bookings.controller.ts index 1d30c4257..854621e0d 100644 --- a/apps/edr-passenger-api/src/modules/bookings/bookings.controller.ts +++ b/apps/edr-passenger-api/src/modules/bookings/bookings.controller.ts @@ -22,7 +22,6 @@ import { ApiBody, } from "@nestjs/swagger"; import { IsPublic } from "@tria-plc/api-common/modules/auth/decorators/public.decorator"; -import { Throttle } from "@nestjs/throttler"; import { BookingsService } from "./bookings.service"; import { GuestBookingService } from "./guest-booking.service"; import { diff --git a/apps/edr-passenger-api/src/modules/health/health.controller.ts b/apps/edr-passenger-api/src/modules/health/health.controller.ts index a918fa76c..02e020d4f 100644 --- a/apps/edr-passenger-api/src/modules/health/health.controller.ts +++ b/apps/edr-passenger-api/src/modules/health/health.controller.ts @@ -1,13 +1,11 @@ import { Controller, Get, HttpStatus, Res } from '@nestjs/common'; import { ApiTags, ApiOperation } from '@nestjs/swagger'; -import { SkipThrottle } from '@nestjs/throttler'; import { IsPublic } from '@tria-plc/api-common/modules/auth/decorators/public.decorator'; import { PrismaService } from '../../common/prisma.service'; import { Response } from 'express'; @ApiTags('Health') @Controller('health') -@SkipThrottle() export class HealthController { constructor(private readonly prisma: PrismaService) {} diff --git a/apps/edr-passenger-api/src/modules/passengers/passengers.controller.ts b/apps/edr-passenger-api/src/modules/passengers/passengers.controller.ts index 502d81a73..20de8ec23 100644 --- a/apps/edr-passenger-api/src/modules/passengers/passengers.controller.ts +++ b/apps/edr-passenger-api/src/modules/passengers/passengers.controller.ts @@ -19,7 +19,6 @@ import { ApiResponse, ApiQuery, } from "@nestjs/swagger"; -import { SkipThrottle, Throttle } from "@nestjs/throttler"; import { PassengersService } from "./passengers.service"; import { CreateTravelerProfileDto, diff --git a/apps/edr-passenger-api/src/modules/payments/internal-payments.controller.ts b/apps/edr-passenger-api/src/modules/payments/internal-payments.controller.ts index 04b721f0c..98262c4c3 100644 --- a/apps/edr-passenger-api/src/modules/payments/internal-payments.controller.ts +++ b/apps/edr-passenger-api/src/modules/payments/internal-payments.controller.ts @@ -7,7 +7,6 @@ import { UseGuards, } from "@nestjs/common"; import { ApiOperation, ApiTags } from "@nestjs/swagger"; -import { SkipThrottle } from "@nestjs/throttler"; import { ServiceAuthGuard } from "../../common/guards/service-auth.guard"; import { PaymentEventDto, MarkPaidResponseDto } from "./internal-payments.dto"; import { PaymentsService } from "./payments.service"; @@ -21,7 +20,6 @@ import { PaymentsService } from "./payments.service"; @ApiTags("Internal Payments") @UseGuards(ServiceAuthGuard) @Controller("internal/payments") -@SkipThrottle() export class InternalPaymentsController { constructor(private readonly paymentsService: PaymentsService) {} diff --git a/apps/edr-passenger-api/src/modules/payments/payments.controller.ts b/apps/edr-passenger-api/src/modules/payments/payments.controller.ts index 918c0b8b8..3c3135832 100644 --- a/apps/edr-passenger-api/src/modules/payments/payments.controller.ts +++ b/apps/edr-passenger-api/src/modules/payments/payments.controller.ts @@ -21,7 +21,6 @@ import { ApiProduces, } from "@nestjs/swagger"; -import { SkipThrottle, Throttle } from "@nestjs/throttler"; import { Response } from "express"; import { PaymentsService } from "./payments.service"; import { diff --git a/apps/edr-passenger-api/src/modules/system-config/system-config.controller.ts b/apps/edr-passenger-api/src/modules/system-config/system-config.controller.ts index 6f2bbb73d..0114c03f9 100644 --- a/apps/edr-passenger-api/src/modules/system-config/system-config.controller.ts +++ b/apps/edr-passenger-api/src/modules/system-config/system-config.controller.ts @@ -1,6 +1,5 @@ import { Body, Controller, Get, Patch, SetMetadata, UseGuards } from '@nestjs/common'; import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger'; -import { SkipThrottle } from '@nestjs/throttler'; import { SystemConfigService } from './system-config.service'; import { IamGuard } from '../../common/iam-adapter'; import { Roles } from '../../common/roles.decorator'; @@ -12,7 +11,6 @@ export class SystemConfigController { @Get('fayda-status') @SetMetadata('isPublic', true) - @SkipThrottle() @ApiOperation({ summary: 'Get Fayda verification enabled status (public)' }) getFaydaStatus() { const enabled = process.env.VERIFAYDA_ENABLED !== 'false'; diff --git a/apps/edr-passenger-api/src/modules/verifayda/verifayda.controller.ts b/apps/edr-passenger-api/src/modules/verifayda/verifayda.controller.ts index 878dc6b36..13de29616 100644 --- a/apps/edr-passenger-api/src/modules/verifayda/verifayda.controller.ts +++ b/apps/edr-passenger-api/src/modules/verifayda/verifayda.controller.ts @@ -15,7 +15,6 @@ import { ApiOperation, ApiTags, } from "@nestjs/swagger"; -import { Throttle } from "@nestjs/throttler"; import type { TCurrentUser } from "@tria-plc/api-common/modules/auth/types/current-user.type"; import { IsPublic } from "@tria-plc/api-common/modules/auth/decorators/public.decorator"; import { JwtGuard } from "../../common/jwt.guard"; diff --git a/apps/edr-passenger-api/src/modules/wallet/wallet.controller.ts b/apps/edr-passenger-api/src/modules/wallet/wallet.controller.ts index 40b6ef91f..d539203f1 100644 --- a/apps/edr-passenger-api/src/modules/wallet/wallet.controller.ts +++ b/apps/edr-passenger-api/src/modules/wallet/wallet.controller.ts @@ -10,7 +10,6 @@ import { Query, } from "@nestjs/common"; import { ApiTags, ApiOperation, ApiBearerAuth } from "@nestjs/swagger"; -import { Throttle } from "@nestjs/throttler"; import { WalletService } from "./wallet.service"; import { JwtGuard } from "../../common/jwt.guard";