Remove rate time

This commit is contained in:
Roba Boru
2026-07-14 10:46:27 +03:00
parent e7aed5a6e4
commit 7cb6d028cf
11 changed files with 1 additions and 79 deletions

View File

@@ -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,

View File

@@ -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<boolean> {
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);
}
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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) {}

View File

@@ -19,7 +19,6 @@ import {
ApiResponse,
ApiQuery,
} from "@nestjs/swagger";
import { SkipThrottle, Throttle } from "@nestjs/throttler";
import { PassengersService } from "./passengers.service";
import {
CreateTravelerProfileDto,

View File

@@ -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) {}

View File

@@ -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 {

View File

@@ -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';

View File

@@ -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";

View File

@@ -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";