1- import { Controller , Get , Param , Query , HttpCode , HttpStatus } from '@nestjs/common' ;
2- import { ApiTags , ApiOperation , ApiResponse , ApiQuery , ApiParam } from '@nestjs/swagger' ;
1+ import {
2+ Controller ,
3+ Get ,
4+ Post ,
5+ Delete ,
6+ Param ,
7+ Body ,
8+ Query ,
9+ ParseUUIDPipe ,
10+ UseGuards ,
11+ HttpCode ,
12+ HttpStatus ,
13+ } from '@nestjs/common' ;
14+ import {
15+ ApiTags ,
16+ ApiOperation ,
17+ ApiResponse ,
18+ ApiQuery ,
19+ ApiParam ,
20+ ApiBearerAuth ,
21+ } from '@nestjs/swagger' ;
22+ import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard' ;
23+ import { CurrentUser } from '../../common/decorators/current-user.decorator' ;
324import { VendorsService } from './vendors.service' ;
425import { VendorResponseDto , VendorType } from './dto/vendor.dto' ;
26+ import { CreateApiKeyDto } from './dto/create-api-key.dto' ;
27+ import { ApiKeyResponseDto , ApiKeyCreatedResponseDto } from './dto/api-key-response.dto' ;
528
629@ApiTags ( 'vendors' )
730@Controller ( 'vendors' )
@@ -26,4 +49,49 @@ export class VendorsController {
2649 async getById ( @Param ( 'id' ) id : string ) : Promise < VendorResponseDto > {
2750 return this . vendorsService . getById ( id ) ;
2851 }
52+
53+ @Post ( 'api-keys' )
54+ @UseGuards ( JwtAuthGuard )
55+ @HttpCode ( HttpStatus . CREATED )
56+ @ApiBearerAuth ( )
57+ @ApiOperation ( { summary : 'Create a new API key for the authenticated vendor' } )
58+ @ApiResponse ( { status : 201 , description : 'API key created' , type : ApiKeyCreatedResponseDto } )
59+ @ApiResponse ( { status : 401 , description : 'Unauthorized' } )
60+ @ApiResponse ( { status : 404 , description : 'Vendor not found' } )
61+ async createApiKey (
62+ @CurrentUser ( ) user : { wallet : string } ,
63+ @Body ( ) dto : CreateApiKeyDto ,
64+ ) : Promise < ApiKeyCreatedResponseDto > {
65+ return this . vendorsService . createApiKey ( user . wallet , dto ) ;
66+ }
67+
68+ @Get ( 'api-keys' )
69+ @UseGuards ( JwtAuthGuard )
70+ @HttpCode ( HttpStatus . OK )
71+ @ApiBearerAuth ( )
72+ @ApiOperation ( { summary : 'List all API keys for the authenticated vendor' } )
73+ @ApiResponse ( { status : 200 , description : 'List of API keys' , type : [ ApiKeyResponseDto ] } )
74+ @ApiResponse ( { status : 401 , description : 'Unauthorized' } )
75+ @ApiResponse ( { status : 404 , description : 'Vendor not found' } )
76+ async listApiKeys (
77+ @CurrentUser ( ) user : { wallet : string } ,
78+ ) : Promise < ApiKeyResponseDto [ ] > {
79+ return this . vendorsService . listApiKeys ( user . wallet ) ;
80+ }
81+
82+ @Delete ( 'api-keys/:id' )
83+ @UseGuards ( JwtAuthGuard )
84+ @HttpCode ( HttpStatus . NO_CONTENT )
85+ @ApiBearerAuth ( )
86+ @ApiOperation ( { summary : 'Revoke an API key' } )
87+ @ApiParam ( { name : 'id' , description : 'API key UUID' } )
88+ @ApiResponse ( { status : 204 , description : 'API key revoked' } )
89+ @ApiResponse ( { status : 401 , description : 'Unauthorized' } )
90+ @ApiResponse ( { status : 404 , description : 'API key not found' } )
91+ async revokeApiKey (
92+ @CurrentUser ( ) user : { wallet : string } ,
93+ @Param ( 'id' , ParseUUIDPipe ) keyId : string ,
94+ ) : Promise < void > {
95+ return this . vendorsService . revokeApiKey ( user . wallet , keyId ) ;
96+ }
2997}
0 commit comments