Skip to content

Commit

Permalink
Merge pull request #1021 from multiversx/SERVICES-1830-extend-account…
Browse files Browse the repository at this point in the history
…-on-analytics

Add account details
  • Loading branch information
danielailie authored Sep 11, 2023
2 parents b4a4bde + baa4856 commit 70254b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ input HistoryPagination {
}

type HoldersCount {
accountDetails: Account!
address: String!
count: Int!
}
Expand Down
6 changes: 6 additions & 0 deletions src/modules/analytics/analytics.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { CollectionDetailsRedisHandler } from './loaders/collection-details.redi
import { ListingAuctionAnalyticsHandler } from './events-parsers/listing-event-analytics.parser';
import { UpdateListingEventParser } from './events-parsers/updateListing-event.parser';
import { UpdatePriceEventParser } from './events-parsers/updatePrice-event.parser';
import { HoldersResolver } from './holders.resolver';
import { AccountsProvider } from '../account-stats/loaders/accounts.loader';
import { AccountsRedisHandler } from '../account-stats/loaders/accounts.redis-handler';

@Module({
providers: [
Expand All @@ -48,6 +51,9 @@ import { UpdatePriceEventParser } from './events-parsers/updatePrice-event.parse
CollectionDetailsRedisHandler,
UpdatePriceEventParser,
UpdateListingEventParser,
AccountsProvider,
AccountsRedisHandler,
HoldersResolver,
],
imports: [
ConfigModule.forRoot({
Expand Down
21 changes: 21 additions & 0 deletions src/modules/analytics/holders.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Resolver, ResolveField, Parent } from '@nestjs/graphql';
import { BaseResolver } from '../common/base.resolver';
import { HoldersCount } from './models/general-stats.model';
import { Account } from '../account-stats/models';
import { AccountsProvider } from '../account-stats/loaders/accounts.loader';

@Resolver(() => HoldersCount)
export class HoldersResolver extends BaseResolver(HoldersCount) {
constructor(private readonly accountsProvider: AccountsProvider) {
super();
}

@ResolveField(() => Account)
async accountDetails(@Parent() holders: HoldersCount) {
const { address } = holders;

if (!address) return null;
const account = await this.accountsProvider.load(address);
return Account.fromEntity(account?.value, address);
}
}
4 changes: 4 additions & 0 deletions src/modules/analytics/models/general-stats.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Field, Int, ObjectType } from '@nestjs/graphql';
import { AnalyticsAggregateValue } from './analytics-aggregate-value';
import { Account } from 'src/modules/account-stats/models';

@ObjectType()
export class GeneralAnalyticsModel {
Expand Down Expand Up @@ -28,6 +29,9 @@ export class HoldersCount {
@Field(() => Int)
count: number;

@Field(() => Account)
accountDetails: Account;

constructor(init?: Partial<HoldersCount>) {
Object.assign(this, init);
}
Expand Down

0 comments on commit 70254b2

Please sign in to comment.