Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

feat: topOffers resolver #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/server-extension/model/topOffers.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Field, ObjectType } from 'type-graphql';

@ObjectType()
export class TopOffers {
@Field(() => String, { nullable: false })
id!: string;

@Field(() => String, { nullable: true})
name!: string;

@Field(() => String, { nullable: false, name: 'collectionId' })
collection_id!: string;

@Field(() => String, { nullable: true, name: 'collectionName' })
collection_name!: string;

@Field(() => Number, { nullable: false, name: 'totalCount' })
total_count!: number;

@Field(() => Number, { nullable: false, name: 'totalAmount' })
total_amount!: number;

@Field(() => Date, { nullable: false })
latest_offer_timestamp!: Date;

// constructor
constructor(props: Partial<TopOffers>) {
Object.assign(this, props);
}
}
13 changes: 13 additions & 0 deletions src/server-extension/query/topOffers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const topOffers = `SELECT
ne.id as id,
ne.name as name,
ce.name as collection_name,
ce.id as collection_id,
o.total_amount as total_amount,
o.total_count as total_count,
o.latest_offer_timestamp as latest_offer_timestamp
FROM (select nft_id, count(id) as total_count, sum(price) as total_amount, max(created_at) as latest_offer_timestamp from offer GROUP BY nft_id) o
LEFT JOIN nft_entity ne on o.nft_id = ne.id
LEFT JOIN collection_entity ce on ne.collection_id = ce.id
;
`;
5 changes: 4 additions & 1 deletion src/server-extension/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { WalletResolver } from './walletResolver';
import { OfferStatsResolver } from './offerStatsResolver';
import { TopOffersResolver } from './topOffersResolver';
import { EventResolver } from './event';

export { WalletResolver, OfferStatsResolver, EventResolver };
export {
WalletResolver, OfferStatsResolver, EventResolver, TopOffersResolver,
};
21 changes: 21 additions & 0 deletions src/server-extension/resolvers/topOffersResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Query, Resolver } from 'type-graphql';
import type { EntityManager } from 'typeorm';
import { Event } from '../../model';
import { makeQuery } from '../utils';
import { topOffers } from '../query/topOffers';
import { TopOffers } from '../model/topOffers.model';

@Resolver()
export class TopOffersResolver {
constructor(private tx: () => Promise<EntityManager>) {}

@Query(() => [TopOffers])
async topOffers(): Promise<TopOffers[]> {
const result: TopOffers[] = await makeQuery(
this.tx,
Event,
topOffers,
);
return result;
}
}