Skip to content

Commit de4f105

Browse files
committed
Merge branch 'development' into API-679-implement-iterate-keys-for-account
2 parents fb127dd + 26038f1 commit de4f105

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/common/indexer/elastic/elastic.indexer.helper.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AddressUtils, BinaryUtils } from "@multiversx/sdk-nestjs-common";
2-
import { AbstractQuery, ElasticQuery, MatchQuery, QueryConditionOptions, QueryOperator, QueryType, RangeGreaterThanOrEqual, RangeLowerThan, RangeLowerThanOrEqual } from "@multiversx/sdk-nestjs-elastic";
2+
import { AbstractQuery, ElasticQuery, MatchQuery, QueryConditionOptions, QueryOperator, QueryType, RangeGreaterThan, RangeGreaterThanOrEqual, RangeLowerThan, RangeLowerThanOrEqual } from "@multiversx/sdk-nestjs-elastic";
33
import { Injectable } from "@nestjs/common";
44
import { ApiConfigService } from "src/common/api-config/api.config.service";
55
import { QueryPagination } from "src/common/entities/query.pagination";
@@ -717,6 +717,14 @@ export class ElasticIndexerHelper {
717717
elasticQuery = elasticQuery.withSearchWildcardCondition(filter.search, ['address', 'api_assets.name']);
718718
}
719719

720+
if (filter.withBalance !== undefined) {
721+
if (filter.withBalance) {
722+
elasticQuery = elasticQuery.withRangeFilter('balanceNum', new RangeGreaterThan(0));
723+
} else {
724+
elasticQuery = elasticQuery.withMustCondition(QueryType.Match('balanceNum', 0));
725+
}
726+
}
727+
720728
return elasticQuery;
721729
}
722730

src/endpoints/accounts/account.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export class AccountController {
152152
@ApiQuery({ name: 'search', description: 'Search by account address, assets name', required: false })
153153
@ApiQuery({ name: 'excludeTags', description: 'Exclude specific tags from result', required: false })
154154
@ApiQuery({ name: 'hasAssets', description: 'Returns a list of accounts that have assets', required: false })
155+
@ApiQuery({ name: 'withBalance', description: 'Filter accounts by balance (true = balance > 0, false = balance = 0)', required: false, type: Boolean })
155156
async getAccountsCount(
156157
@Query("ownerAddress", ParseAddressPipe) ownerAddress?: string,
157158
@Query("isSmartContract", ParseBoolPipe) isSmartContract?: boolean,
@@ -160,6 +161,7 @@ export class AccountController {
160161
@Query("excludeTags", ParseArrayPipe) excludeTags?: string[],
161162
@Query("hasAssets", ParseBoolPipe) hasAssets?: boolean,
162163
@Query("search") search?: string,
164+
@Query("withBalance", ParseBoolPipe) withBalance?: boolean,
163165
): Promise<number> {
164166
return await this.accountService.getAccountsCount(
165167
new AccountQueryOptions(
@@ -171,6 +173,7 @@ export class AccountController {
171173
excludeTags,
172174
hasAssets,
173175
search,
176+
withBalance,
174177
}));
175178
}
176179

@@ -184,6 +187,7 @@ export class AccountController {
184187
@Query("excludeTags", ParseArrayPipe) excludeTags?: string[],
185188
@Query("hasAssets", ParseBoolPipe) hasAssets?: boolean,
186189
@Query("search") search?: string,
190+
@Query("withBalance", ParseBoolPipe) withBalance?: boolean,
187191
): Promise<number> {
188192
return await this.accountService.getAccountsCount(
189193
new AccountQueryOptions(
@@ -195,6 +199,7 @@ export class AccountController {
195199
excludeTags,
196200
hasAssets,
197201
search,
202+
withBalance,
198203
}));
199204
}
200205

src/endpoints/accounts/entities/account.query.options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class AccountQueryOptions {
2222
excludeTags?: string[];
2323
hasAssets?: boolean;
2424
search?: string;
25+
withBalance?: boolean;
2526

2627
validate(size: number) {
2728
if (this.withDeployInfo && size > 25) {
@@ -53,6 +54,7 @@ export class AccountQueryOptions {
5354
this.excludeTags !== undefined ||
5455
this.hasAssets !== undefined ||
5556
this.search !== undefined ||
56-
this.addresses !== undefined;
57+
this.addresses !== undefined ||
58+
this.withBalance !== undefined;
5759
}
5860
}

0 commit comments

Comments
 (0)