Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: resolver on hotdashboard #96

Merged
merged 9 commits into from
Oct 18, 2022
20 changes: 20 additions & 0 deletions src/server-extension/model/hot.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Field, ObjectType } from 'type-graphql';

@ObjectType()
export class HotNFTEntity {
@Field(() => Date, { nullable: false })
timestamp!: Date

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

@Field(() => String, { nullable: false, name: "collectionName" })
collection_name!: string

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

constructor(props: Partial<HotNFTEntity>) {
Object.assign(this, props);
}
}
17 changes: 16 additions & 1 deletion src/server-extension/query/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ FROM nft_entity ne
where
e.interaction = 'BUY'
and e.timestamp >= NOW() - INTERVAL '7 DAY'
ORDER BY e.timestamp desc`
ORDER BY e.timestamp desc`
KngZhi marked this conversation as resolved.
Show resolved Hide resolved

export const hotDashboardQuery = (dateRange: string) => `SELECT
e.timestamp,
e.meta,
ce.name as collection_name,
ce.id as collection_id
FROM
event e
LEFT JOIN nft_entity ne ON e.nft_id = ne.id
LEFT JOIN collection_entity ce ON ne.collection_id = ce.id
WHERE
e.interaction = 'BUY'
AND e."timestamp" >= NOW() - INTERVAL '${dateRange}'
KngZhi marked this conversation as resolved.
Show resolved Hide resolved
ORDER BY
e.timestamp`
23 changes: 23 additions & 0 deletions src/server-extension/resolvers/hotDashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Arg, Query, Resolver, } from 'type-graphql'
import type { EntityManager } from 'typeorm'
import { NFTEntity } from '../../model/generated'
import { HotNFTEntity } from '../model/hot.model'
import { hotDashboardQuery } from "../query/nft";
import { makeQuery } from "../utils";

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

@Query(() => [HotNFTEntity])
async hotDashboard(
@Arg('dateRange', { nullable: false, defaultValue: '7 DAY' }) dateRange: string,
): Promise<[HotNFTEntity]> {
const result: [HotNFTEntity] = await makeQuery(
this.tx,
NFTEntity,
hotDashboardQuery(dateRange))

return result
}
}
2 changes: 2 additions & 0 deletions src/server-extension/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CollectionChartResolver } from './collectionChart'
import { CollectionEventResolver } from './collectionEvent'
import { PassionFeedResolver } from "./passionFeed";
import { SalesFeedResolver } from "./salesFeed";
import { HotDashboardResolver } from "./hotDashboard";

@ObjectType()
export class Hello {
Expand Down Expand Up @@ -39,4 +40,5 @@ export {
CollectionEventResolver,
PassionFeedResolver,
SalesFeedResolver,
HotDashboardResolver,
}