diff --git a/src/constants/error.constant.ts b/src/constants/error.constant.ts index e7ebaf8..adf0dfd 100644 --- a/src/constants/error.constant.ts +++ b/src/constants/error.constant.ts @@ -1,6 +1,7 @@ export enum EError { OTHER_SYSTEM_ERROR = 'OTHER_SYSTEM_ERROR', FORBIDDEN_RESOURCE = 'FORBIDDEN_RESOURCE', + ACTION_CANNOT_PROCESSED = 'ACTION_CANNOT_PROCESSED', DUPLICATED_ACTION = 'DUPLICATED_ACTION', USER_NOT_FOUND = 'USER_NOT_FOUND', WRONG_EMAIL_OR_PASS = 'WRONG_EMAIL_OR_PASS', diff --git a/src/modules/users/admin.service.ts b/src/modules/users/admin.service.ts index a5f42fa..8380e5b 100644 --- a/src/modules/users/admin.service.ts +++ b/src/modules/users/admin.service.ts @@ -27,7 +27,7 @@ export class AdminService { ) {} async createNewToken(payload: CreateTokenReqDto) { if (await this.checkTokenExist(payload.assetAddress)) { - httpBadRequest(EError.DUPLICATED_ACTION); + return httpBadRequest(EError.DUPLICATED_ACTION); } const [symbol, decimals] = await Promise.all([ this.erc20ContractTemplate.getTokenSymbol(payload.assetAddress), @@ -67,4 +67,15 @@ export class AdminService { const [tokens, count] = await this.commonConfigRepo.getManyAndPagination(payload); return toPageDto(tokens, payload, count); } + async redeployToken(tokenPairId: number) { + const tokenInfo = await this.commonConfigRepo.findOneBy({ id: tokenPairId }); + if (!tokenInfo) { + httpBadRequest(EError.RESOURCE_NOT_FOUND); + } + if (tokenInfo.status !== ETokenPairStatus.DEPLOY_FAILED) { + return httpBadRequest(EError.ACTION_CANNOT_PROCESSED); + } + + await this.tokenDeployerService.deployTokenMina(tokenInfo.id); + } } diff --git a/src/shared/exceptions/http-exeption.ts b/src/shared/exceptions/http-exeption.ts index eed3ba3..dcc7d30 100644 --- a/src/shared/exceptions/http-exeption.ts +++ b/src/shared/exceptions/http-exeption.ts @@ -9,7 +9,7 @@ import { import { EError } from '../../constants/error.constant.js'; // 400 -export function httpBadRequest(errorCode: EError, metaData?: object) { +export function httpBadRequest(errorCode: EError, metaData?: object): never { throw new BadRequestException({ statusCode: 400, errorCode, @@ -18,7 +18,7 @@ export function httpBadRequest(errorCode: EError, metaData?: object) { } // 401 -export function httpUnAuthorized(errorCode?: EError, metaData?: object) { +export function httpUnAuthorized(errorCode?: EError, metaData?: object): never { throw new UnauthorizedException({ statusCode: 401, errorCode: errorCode || EError.UNAUTHORIZED, @@ -27,7 +27,7 @@ export function httpUnAuthorized(errorCode?: EError, metaData?: object) { } // 403 -export function httpForbidden(errorCode?: EError, metaData?: object) { +export function httpForbidden(errorCode?: EError, metaData?: object): never { throw new ForbiddenException({ statusCode: 403, errorCode: errorCode || EError.FORBIDDEN_RESOURCE, @@ -36,7 +36,7 @@ export function httpForbidden(errorCode?: EError, metaData?: object) { } // 404 -export function httpNotFound(errorCode: EError, metaData?: object) { +export function httpNotFound(errorCode: EError, metaData?: object): never { throw new NotFoundException({ statusCode: 404, errorCode,