Skip to content

Commit

Permalink
Merge pull request #243 from sotatek-dev/feat/add-token
Browse files Browse the repository at this point in the history
Feat/add token
  • Loading branch information
Sotatek-TanHoang authored Jan 8, 2025
2 parents b574e99 + b200aee commit 280e9db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/database/repositories/common-configuration.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ export class CommonConfigRepository extends BaseRepository<CommonConfig> {
return this.createQueryBuilder(`${this.alias}`).select().getOne();
}

public getManyAndPagination(dto: GetTokensReqDto) {
public getManyAndPagination(dto: GetTokensReqDto, role: 'user' | 'admin' = 'admin') {
const qb = this.createQb();
qb.select();
if (isArray(dto.statuses)) {
qb.andWhere({ status: In(dto.statuses) });
}
if (isNotEmpty(dto.assetName)) {
qb.andWhere({ asset: ILike(`${dto.assetName}%`) });
qb.andWhere({ asset: ILike(`%${dto.assetName}%`) });
}
if (role === 'user') {
qb.andWhere({ isHidden: false });
}
if (isNotEmpty(dto.tokenAddress)) {
qb.andWhere(
Expand All @@ -33,6 +36,7 @@ export class CommonConfigRepository extends BaseRepository<CommonConfig> {
}),
);
}

qb.orderBy('id', 'DESC');
this.queryBuilderAddPagination(qb, dto);
return qb.getManyAndCount();
Expand Down
6 changes: 3 additions & 3 deletions src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ETableName } from '../../constants/entity.constant.js';
import { GuardPublic } from '../../guards/guard.decorator.js';
import { EstimateBridgeRequestDto } from './dto/estimate-bridge-request.dto.js';
import { GetHistoryOfUserDto, GetHistoryOfUserResponseDto } from './dto/history-response.dto.js';
import { GetProtocolFeeBodyDto } from './dto/user-request.dto.js';
import { GetProtocolFeeBodyDto, GetTokensReqDto } from './dto/user-request.dto.js';
import {
EstimateBridgeResponseDto,
GetListTokenPairResponseDto,
Expand Down Expand Up @@ -36,8 +36,8 @@ export class UsersController {
@Get('list-supported-pairs')
@GuardPublic()
@ApiOkResponse({ type: [GetListTokenPairResponseDto] })
getListTokenPair() {
return this.userService.getListTokenPair();
getListTokenPair(@Query() query: GetTokensReqDto) {
return this.userService.getListTokenPair(query);
}

@Post('bridge/protocol-fee')
Expand Down
19 changes: 9 additions & 10 deletions src/modules/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { LoggerService } from '../../shared/modules/logger/logger.service.js';
import { RedisClientService } from '../../shared/modules/redis/redis-client.service.js';
import { UpdateCommonConfigBodyDto, UpdateTokenPairVisibilityReqDto } from './dto/common-config-request.dto.js';
import { GetHistoryDto, GetHistoryOfUserDto } from './dto/history-response.dto.js';
import { GetProtocolFeeBodyDto } from './dto/user-request.dto.js';
import { GetProtocolFeeBodyDto, GetTokensReqDto } from './dto/user-request.dto.js';
import { GetProofOfAssetsResponseDto, GetTokensPriceResponseDto } from './dto/user-response.dto.js';

@Injectable()
Expand Down Expand Up @@ -72,16 +72,15 @@ export class UsersService {
return { dailyQuota, totalAmountOfToDay: totalamount?.totalamount || 0 };
}

async getListTokenPair() {
return this.commonConfigRepository.find({
where: {
status: ETokenPairStatus.ENABLE,
isHidden: false,
async getListTokenPair(payload: GetTokensReqDto) {
const [data] = await this.commonConfigRepository.getManyAndPagination(
{
...payload,
statuses: [ETokenPairStatus.ENABLE],
},
order: {
id: 'DESC',
},
});
'user',
);
return data;
}

async getProtocolFee(dto: GetProtocolFeeBodyDto) {
Expand Down

0 comments on commit 280e9db

Please sign in to comment.