Skip to content

Commit

Permalink
Merge pull request #69 from sotatek-dev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Sotatek-TanHoang authored Sep 24, 2024
2 parents ebf54ab + 6398006 commit 126aa09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/database/repositories/event-log.repository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GetHistoryDto } from 'modules/users/dto/history-response.dto.js';
import { EntityRepository } from 'nestjs-typeorm-custom-repository';
import { Brackets } from 'typeorm';

Expand Down Expand Up @@ -103,11 +104,16 @@ export class EventLogRepository extends BaseRepository<EventLog> {
return queryBuilder.getManyAndCount();
}

public async getHistories(options) {
public async getHistories(options: GetHistoryDto) {
const queryBuilder = this.createQb();
queryBuilder.orderBy(`${this.alias}.id`, EDirection.DESC);
if (options.address) {
queryBuilder.andWhere(`${this.alias}.sender_address = :address`, { address: options.address });
if (typeof options.address === 'string') {
queryBuilder.andWhere(
`${this.alias}.sender_address ilike :address OR ${this.alias}.receive_address ilike :address`,
{
address: `%${options.address.toLowerCase()}%`,
},
);
}

this.queryBuilderAddPagination(queryBuilder, options);
Expand Down
6 changes: 6 additions & 0 deletions src/modules/crawler/crawler.evmbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export class BlockchainEVMCrawler {
await queryRunner.startTransaction();
try {
const { startBlockNumber, toBlock } = await this.getFromToBlock();
if (startBlockNumber > toBlock) {
this.logger.info(
`Block <${startBlockNumber}> is the newest block can be processed (on network: ${toBlock}). Wait for the next tick...`,
);
return;
}
const events = await this.ethBridgeContract.getEvent(startBlockNumber, toBlock);

for (const event of events) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/users/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { AuthAdminGuard } from '../../shared/decorators/http.decorator.js';
import { UpdateCommonConfigBodyDto } from './dto/common-config-request.dto.js';
import { GetCommonConfigResponseDto } from './dto/common-config-response.dto.js';
import { GetHistoryOfUserDto, GetHistoryOfUserResponseDto } from './dto/history-response.dto.js';
import { GetHistoryDto, GetHistoryOfUserResponseDto } from './dto/history-response.dto.js';
import { UsersService } from './users.service.js';

@ApiTags('Admins')
Expand All @@ -17,7 +17,7 @@ export class AdminController {
@AuthAdminGuard()
@UseGuards(AuthGuard('jwt'))
@ApiOkResponse({ type: [GetHistoryOfUserResponseDto] })
getHistoriesOfUser(@Query() query: GetHistoryOfUserDto) {
getHistoriesOfUser(@Query() query: GetHistoryDto) {
return this.userService.getHistories(query);
}

Expand Down

0 comments on commit 126aa09

Please sign in to comment.