Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@nestjs/platform-express": "11.1.6",
"@nestjs/schedule": "^6.0.0",
"@nestjs/swagger": "^11.2.0",
"@nestjs/throttler": "^6.4.0",
"@nestjs/typeorm": "^11.0.0",
"@nestjsx/crud": "4.6.2",
"@rocketadmin/shared-code": "workspace:*",
Expand Down
16 changes: 15 additions & 1 deletion backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { ScheduleModule } from '@nestjs/schedule';
import { DataSource } from 'typeorm';
import { AppController } from './app.controller.js';
Expand Down Expand Up @@ -36,10 +36,20 @@ import { SaasModule } from './microservices/saas-microservice/saas.module.js';
import { AppLoggerMiddleware } from './middlewares/logging-middleware/app-logger-middlewate.js';
import { DatabaseModule } from './shared/database/database.module.js';
import { GetHelloUseCase } from './use-cases-app/get-hello.use.case.js';
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';

@Module({
imports: [
ScheduleModule.forRoot(),
ThrottlerModule.forRoot({
throttlers: [
{
ttl: 60000,
limit: 10,
},
],
skipIf: () => true,
}),
ConnectionModule,
ConnectionPropertiesModule,
ConversionModule,
Expand Down Expand Up @@ -75,6 +85,10 @@ import { GetHelloUseCase } from './use-cases-app/get-hello.use.case.js';
provide: APP_INTERCEPTOR,
useClass: TimeoutInterceptor,
},
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
},
{
provide: BaseType.GLOBAL_DB_CONTEXT,
useClass: GlobalDatabaseContext,
Expand Down
2 changes: 2 additions & 0 deletions backend/src/entities/company-info/company-info.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Throttle } from '@nestjs/throttler';
import { Request, Response } from 'express';
import { UseCaseType } from '../../common/data-injection.tokens.js';
import { SlugUuid } from '../../decorators/slug-uuid.decorator.js';
Expand Down Expand Up @@ -204,6 +205,7 @@ export class CompanyInfoController {
type: FoundUserFullCompanyInfoDs,
})
@UseGuards(CompanyUserGuard)
@Throttle({ default: { limit: 5, ttl: 60000 } })
@Get('my/full')
async getUserCompanies(@UserId() userId: string): Promise<FoundUserCompanyInfoDs | FoundUserFullCompanyInfoDs> {
return await this.getUserFullCompanyInfoUseCase.execute(userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { HttpException, HttpStatus, Inject, Injectable, Scope } from '@nestjs/common';
import AbstractUseCase from '../../../common/abstract-use.case.js';
import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js';
import { BaseType } from '../../../common/data-injection.tokens.js';
Expand All @@ -14,7 +14,7 @@ import { CompanyInfoEntity } from '../company-info.entity.js';
import { buildFoundCompanyFullInfoDs, buildFoundCompanyInfoDs } from '../utils/build-found-company-info-ds.js';
import { IGetUserFullCompanyInfo } from './company-info-use-cases.interface.js';

@Injectable()
@Injectable({ scope: Scope.REQUEST })
export class GetUserCompanyFullInfoUseCase
extends AbstractUseCase<string, FoundUserCompanyInfoDs>
implements IGetUserFullCompanyInfo
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,17 @@ __metadata:
languageName: node
linkType: hard

"@nestjs/throttler@npm:^6.4.0":
version: 6.4.0
resolution: "@nestjs/throttler@npm:6.4.0"
peerDependencies:
"@nestjs/common": ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
"@nestjs/core": ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
reflect-metadata: ^0.1.13 || ^0.2.0
checksum: 056d7d2874ab02303af02239661257a291edef9b57e75e99686b48eae376d88d513211f21d68655e4d673838c7c46d85a5fb1575ce7945a5c08a7d05a1ce46fe
languageName: node
linkType: hard

"@nestjs/typeorm@npm:^11.0.0":
version: 11.0.0
resolution: "@nestjs/typeorm@npm:11.0.0"
Expand Down Expand Up @@ -5631,6 +5642,7 @@ __metadata:
"@nestjs/schematics": 11.0.7
"@nestjs/swagger": ^11.2.0
"@nestjs/testing": ^11.1.6
"@nestjs/throttler": ^6.4.0
"@nestjs/typeorm": ^11.0.0
"@nestjsx/crud": 4.6.2
"@rocketadmin/shared-code": "workspace:*"
Expand Down
Loading