@@ -11,89 +11,91 @@ import { FoundApiKeyDto } from './application/dto/found-api-key.dto.js';
1111import { ICreateApiKey , IDeleteApiKey , IGetApiKey , IGetApiKeys } from './use-cases/api-key-use-cases.interface.js' ;
1212import { buildCreatedApiKeyDto } from './utils/build-created-api-key.dto.js' ;
1313import { buildFoundApiKeyDto } from './utils/build-found-api-key.dto.js' ;
14+ import { Timeout } from '../../decorators/timeout.decorator.js' ;
1415
1516@UseInterceptors ( SentryInterceptor )
17+ @Timeout ( )
1618@Controller ( )
1719@ApiBearerAuth ( )
1820@ApiTags ( 'Api Key' )
1921@Injectable ( )
2022export class ApiKeyController {
21- constructor (
22- @Inject ( UseCaseType . CREATE_API_KEY )
23- private readonly createApiKeyUseCase : ICreateApiKey ,
24- @Inject ( UseCaseType . GET_API_KEYS )
25- private readonly getApiKeysUseCase : IGetApiKeys ,
26- @Inject ( UseCaseType . GET_API_KEY )
27- private readonly getApiKeyUseCase : IGetApiKey ,
28- @Inject ( UseCaseType . DELETE_API_KEY )
29- private readonly deleteApiKeyUseCase : IDeleteApiKey ,
30- ) { }
23+ constructor (
24+ @Inject ( UseCaseType . CREATE_API_KEY )
25+ private readonly createApiKeyUseCase : ICreateApiKey ,
26+ @Inject ( UseCaseType . GET_API_KEYS )
27+ private readonly getApiKeysUseCase : IGetApiKeys ,
28+ @Inject ( UseCaseType . GET_API_KEY )
29+ private readonly getApiKeyUseCase : IGetApiKey ,
30+ @Inject ( UseCaseType . DELETE_API_KEY )
31+ private readonly deleteApiKeyUseCase : IDeleteApiKey ,
32+ ) { }
3133
32- @ApiOperation ( { summary : 'Create new API key' } )
33- @ApiResponse ( {
34- status : 200 ,
35- description : 'Api key created.' ,
36- type : CreatedApiKeyDto ,
37- } )
38- @Post ( '/apikey' )
39- public async createApiKey ( @UserId ( ) userId : string , @Body ( ) apiKeyData : CreateApiKeyDto ) : Promise < CreatedApiKeyDto > {
40- const apiKey = await this . createApiKeyUseCase . execute (
41- {
42- userId,
43- title : apiKeyData . title ,
44- } ,
45- InTransactionEnum . ON ,
46- ) ;
47- return buildCreatedApiKeyDto ( apiKey ) ;
48- }
34+ @ApiOperation ( { summary : 'Create new API key' } )
35+ @ApiResponse ( {
36+ status : 200 ,
37+ description : 'Api key created.' ,
38+ type : CreatedApiKeyDto ,
39+ } )
40+ @Post ( '/apikey' )
41+ public async createApiKey ( @UserId ( ) userId : string , @Body ( ) apiKeyData : CreateApiKeyDto ) : Promise < CreatedApiKeyDto > {
42+ const apiKey = await this . createApiKeyUseCase . execute (
43+ {
44+ userId,
45+ title : apiKeyData . title ,
46+ } ,
47+ InTransactionEnum . ON ,
48+ ) ;
49+ return buildCreatedApiKeyDto ( apiKey ) ;
50+ }
4951
50- @ApiOperation ( { summary : 'Get all user api keys' } )
51- @ApiResponse ( {
52- status : 200 ,
53- description : 'Get all user api keys.' ,
54- type : FoundApiKeyDto ,
55- isArray : true ,
56- } )
57- @Get ( '/apikeys' )
58- public async getApiKeys ( @UserId ( ) userId : string ) : Promise < Array < FoundApiKeyDto > > {
59- const foundApiKeys = await this . getApiKeysUseCase . execute ( userId ) ;
60- return foundApiKeys . map ( ( apiKey ) => buildFoundApiKeyDto ( apiKey ) ) ;
61- }
52+ @ApiOperation ( { summary : 'Get all user api keys' } )
53+ @ApiResponse ( {
54+ status : 200 ,
55+ description : 'Get all user api keys.' ,
56+ type : FoundApiKeyDto ,
57+ isArray : true ,
58+ } )
59+ @Get ( '/apikeys' )
60+ public async getApiKeys ( @UserId ( ) userId : string ) : Promise < Array < FoundApiKeyDto > > {
61+ const foundApiKeys = await this . getApiKeysUseCase . execute ( userId ) ;
62+ return foundApiKeys . map ( ( apiKey ) => buildFoundApiKeyDto ( apiKey ) ) ;
63+ }
6264
63- @ApiOperation ( { summary : 'Get api key by id' } )
64- @ApiResponse ( {
65- status : 200 ,
66- description : 'Get api key by id.' ,
67- type : FoundApiKeyDto ,
68- } )
69- @Get ( '/apikey/:apiKeyId' )
70- public async getApiKey ( @UserId ( ) userId : string , @SlugUuid ( 'apiKeyId' ) apiKeyId : string ) : Promise < FoundApiKeyDto > {
71- const foundApiKey = await this . getApiKeyUseCase . execute ( { userId, apiKeyId } ) ;
72- return buildFoundApiKeyDto ( foundApiKey ) ;
73- }
65+ @ApiOperation ( { summary : 'Get api key by id' } )
66+ @ApiResponse ( {
67+ status : 200 ,
68+ description : 'Get api key by id.' ,
69+ type : FoundApiKeyDto ,
70+ } )
71+ @Get ( '/apikey/:apiKeyId' )
72+ public async getApiKey ( @UserId ( ) userId : string , @SlugUuid ( 'apiKeyId' ) apiKeyId : string ) : Promise < FoundApiKeyDto > {
73+ const foundApiKey = await this . getApiKeyUseCase . execute ( { userId, apiKeyId } ) ;
74+ return buildFoundApiKeyDto ( foundApiKey ) ;
75+ }
7476
75- @ApiOperation ( { summary : 'Delete api key by id' } )
76- @ApiResponse ( {
77- status : 200 ,
78- description : 'Get api key by id.' ,
79- type : FoundApiKeyDto ,
80- } )
81- @Delete ( '/apikey/:apiKeyId' )
82- public async deleteApiKey ( @UserId ( ) userId : string , @SlugUuid ( 'apiKeyId' ) apiKeyId : string ) : Promise < FoundApiKeyDto > {
83- const deletedApiKey = await this . deleteApiKeyUseCase . execute ( { userId, apiKeyId } , InTransactionEnum . ON ) ;
84- return buildFoundApiKeyDto ( deletedApiKey ) ;
85- }
77+ @ApiOperation ( { summary : 'Delete api key by id' } )
78+ @ApiResponse ( {
79+ status : 200 ,
80+ description : 'Get api key by id.' ,
81+ type : FoundApiKeyDto ,
82+ } )
83+ @Delete ( '/apikey/:apiKeyId' )
84+ public async deleteApiKey ( @UserId ( ) userId : string , @SlugUuid ( 'apiKeyId' ) apiKeyId : string ) : Promise < FoundApiKeyDto > {
85+ const deletedApiKey = await this . deleteApiKeyUseCase . execute ( { userId, apiKeyId } , InTransactionEnum . ON ) ;
86+ return buildFoundApiKeyDto ( deletedApiKey ) ;
87+ }
8688
87- @ApiOperation ( { summary : 'Check api key' } )
88- @ApiResponse ( {
89- status : 200 ,
90- description : 'Api key is valid.' ,
91- } )
92- @Get ( '/check/apikey' )
93- public async checkApiKey ( ) : Promise < any > {
94- return {
95- result : true ,
96- message : 'Api key is valid' ,
97- } ;
98- }
89+ @ApiOperation ( { summary : 'Check api key' } )
90+ @ApiResponse ( {
91+ status : 200 ,
92+ description : 'Api key is valid.' ,
93+ } )
94+ @Get ( '/check/apikey' )
95+ public async checkApiKey ( ) : Promise < any > {
96+ return {
97+ result : true ,
98+ message : 'Api key is valid' ,
99+ } ;
100+ }
99101}
0 commit comments