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: sales feed #86

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions src/server-extension/model/sales.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Field, ObjectType } from 'type-graphql';

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

@Field(() => String)
name!: string

@Field(() => String, { nullable: false })
issuer!: string

@Field(() => String, { nullable: false })
buyer!: string

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

@Field(() => BigInt, { nullable: false, name: 'salePrice' })
sale_price!: bigint

@Field(() => String, { nullable: false })
timestamp!: string

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

constructor(props: Partial<SaleNftEntity>) {
Object.assign(this, props);
}
}
19 changes: 18 additions & 1 deletion src/server-extension/query/nft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
export const passionQuery = `SELECT DISTINCT ne.issuer as id
FROM nft_entity ne
WHERE ne.current_owner = $1
AND ne.current_owner != ne.issuer`
AND ne.current_owner != ne.issuer`

export const salesQuery = `SELECT
ne.id,
ne.name,
ne.issuer,
e.caller as buyer,
collection_id,
(e.meta::bigint) as sale_price,
e.timestamp,
me.image
FROM
nft_entity ne
LEFT join event as e on e.nft_id = ne.id
LEFT join metadata_entity me on me.id = ne.metadata
where
e.interaction = 'BUY'
and e.timestamp >= NOW() - INTERVAL '10 DAY'`
KngZhi marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/server-extension/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SpotlightResolver } from './spotlight'
import { CollectionChartResolver } from './collectionChart'
import { CollectionEventResolver } from './collectionEvent'
import { PassionFeedResolver } from "./passionFeed";
import { SalesFeedResolver } from "./salesFeed";

@ObjectType()
export class Hello {
Expand Down Expand Up @@ -37,4 +38,5 @@ export {
SpotlightResolver,
CollectionEventResolver,
PassionFeedResolver,
SalesFeedResolver,
}
18 changes: 18 additions & 0 deletions src/server-extension/resolvers/salesFeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Query, Resolver } from 'type-graphql'
import type { EntityManager } from 'typeorm'
import { NFTEntity } from '../../model/generated'
import { SaleNftEntity } from '../model/sales.model'
import { salesQuery } from "../query/nft";
import { makeQuery } from "../utils";

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

@Query(() => [SaleNftEntity])
async salesFeed(): Promise<[SaleNftEntity]> {
const result: [SaleNftEntity] = await makeQuery(this.tx, NFTEntity, salesQuery)

return result
}
}
KngZhi marked this conversation as resolved.
Show resolved Hide resolved