@@ -18,6 +18,7 @@ import {
1818import {
1919 ApiKeyGetGuard ,
2020 ApiKeyUpdateActiveGuard ,
21+ ApiKeyUpdateGuard ,
2122 ApiKeyUpdateInactiveGuard ,
2223 ApiKeyUpdateResetGuard ,
2324} from 'src/common/api-key/decorators/api-key.admin.decorator' ;
@@ -29,9 +30,12 @@ import {
2930 ApiKeyInactiveDoc ,
3031 ApiKeyListDoc ,
3132 ApiKeyResetDoc ,
33+ ApiKeyUpdateDoc ,
3234} from 'src/common/api-key/docs/api-key.admin.doc' ;
3335import { ApiKeyCreateDto } from 'src/common/api-key/dtos/api-key.create.dto' ;
3436import { ApiKeyRequestDto } from 'src/common/api-key/dtos/api-key.request.dto' ;
37+ import { ApiKeyUpdateDateDto } from 'src/common/api-key/dtos/api-key.update-date.dto' ;
38+ import { ApiKeyUpdateNameDto } from 'src/common/api-key/dtos/api-key.update-name.dto' ;
3539import { IApiKeyEntity } from 'src/common/api-key/interfaces/api-key.interface' ;
3640import { ApiKeyEntity } from 'src/common/api-key/repository/entities/api-key.entity' ;
3741import { ApiKeyCreateSerialization } from 'src/common/api-key/serializations/api-key.create.serialization' ;
@@ -58,6 +62,7 @@ import {
5862 IResponse ,
5963 IResponsePaging ,
6064} from 'src/common/response/interfaces/response.interface' ;
65+ import { ResponseIdSerialization } from 'src/common/response/serializations/response.id.serialization' ;
6166
6267@ApiTags ( 'admin.apiKey' )
6368@Controller ( {
@@ -225,7 +230,7 @@ export class ApiKeyAdminController {
225230 ENUM_AUTH_PERMISSIONS . API_KEY_RESET
226231 )
227232 @AuthJwtAdminAccessProtected ( )
228- @Put ( '/update/:apiKey/reset' )
233+ @Patch ( '/update/:apiKey/reset' )
229234 async reset ( @GetApiKey ( ) apiKey : ApiKeyEntity ) : Promise < IResponse > {
230235 try {
231236 const updated : IApiKeyEntity = await this . apiKeyService . reset (
@@ -245,4 +250,59 @@ export class ApiKeyAdminController {
245250 } ) ;
246251 }
247252 }
253+
254+ @ApiKeyUpdateDoc ( )
255+ @Response ( 'apiKey.update' , { serialization : ResponseIdSerialization } )
256+ @ApiKeyUpdateGuard ( )
257+ @RequestParamGuard ( ApiKeyRequestDto )
258+ @AuthPermissionProtected (
259+ ENUM_AUTH_PERMISSIONS . API_KEY_READ ,
260+ ENUM_AUTH_PERMISSIONS . API_KEY_UPDATE
261+ )
262+ @AuthJwtAdminAccessProtected ( )
263+ @Put ( '/update/:apiKey' )
264+ async updateName (
265+ @Body ( ) body : ApiKeyUpdateNameDto ,
266+ @GetApiKey ( ) apiKey : ApiKeyEntity
267+ ) : Promise < IResponse > {
268+ try {
269+ await this . apiKeyService . updateName ( apiKey . _id , body ) ;
270+ } catch ( err : any ) {
271+ throw new InternalServerErrorException ( {
272+ statusCode : ENUM_ERROR_STATUS_CODE_ERROR . ERROR_UNKNOWN ,
273+ message : 'http.serverError.internalServerError' ,
274+ error : err . message ,
275+ } ) ;
276+ }
277+
278+ return { _id : apiKey . _id } ;
279+ }
280+
281+ @ApiKeyUpdateDoc ( )
282+ @Response ( 'apiKey.updateDate' , { serialization : ResponseIdSerialization } )
283+ @ApiKeyUpdateGuard ( )
284+ @RequestParamGuard ( ApiKeyRequestDto )
285+ @AuthPermissionProtected (
286+ ENUM_AUTH_PERMISSIONS . API_KEY_READ ,
287+ ENUM_AUTH_PERMISSIONS . API_KEY_UPDATE ,
288+ ENUM_AUTH_PERMISSIONS . API_KEY_UPDATE_DATE
289+ )
290+ @AuthJwtAdminAccessProtected ( )
291+ @Put ( '/update/:apiKey/date' )
292+ async updateDate (
293+ @Body ( ) body : ApiKeyUpdateDateDto ,
294+ @GetApiKey ( ) apiKey : ApiKeyEntity
295+ ) : Promise < IResponse > {
296+ try {
297+ await this . apiKeyService . updateDate ( apiKey . _id , body ) ;
298+ } catch ( err : any ) {
299+ throw new InternalServerErrorException ( {
300+ statusCode : ENUM_ERROR_STATUS_CODE_ERROR . ERROR_UNKNOWN ,
301+ message : 'http.serverError.internalServerError' ,
302+ error : err . message ,
303+ } ) ;
304+ }
305+
306+ return { _id : apiKey . _id } ;
307+ }
248308}
0 commit comments