change sth

This commit is contained in:
CounterFire2023 2023-06-29 18:36:35 +08:00
parent 5ceb0445b7
commit 4424e44416
2 changed files with 49 additions and 1 deletions

View File

@ -22,6 +22,46 @@ export class NftHolderClass extends BaseModule {
public version: number
@prop()
public lastTxHash: string
public toQlModel() {
return {
id: this.tokenId,
address: this.user,
chain: this.chain + '',
contract: this.address,
}
}
public static async queryNFT({
address,
chain,
contract,
id,
}: {
address?: string
chain?: string
contract?: string
id?: string
}) {
chain = chain || process.env.CHAIN_DEFAULT
const chainNum = parseInt(chain)
const query: any = { chain: chainNum }
if (address) {
query.user = address.toLowerCase()
}
if (contract) {
query.address = contract.toLowerCase()
}
if (id) {
query.tokenId = id
}
let records = await NftHolder.find(query)
let results: any = []
for (let record of records) {
results.push(record.toQlModel())
}
return results
}
}
export const NftHolder = getModelForClass(NftHolderClass, {

View File

@ -1,3 +1,4 @@
import { NftHolder } from 'models/NftHolder'
import { RequestTask } from 'models/RequestTask'
const graphql = require('graphql')
@ -11,6 +12,7 @@ const nftType = new GraphQLObjectType({
address: { type: GraphQLString },
contract: { type: GraphQLString },
id: { type: GraphQLString },
chain: { type: GraphQLString },
}),
})
@ -27,8 +29,14 @@ const RootQuery = new GraphQLObjectType({
},
nfts: {
type: new GraphQLList(nftType),
args: {
address: { type: GraphQLString },
contract: { type: GraphQLString },
id: { type: GraphQLString },
chain: { type: GraphQLString },
},
async resolve(parent, args) {
return await RequestTask.find(args)
return await NftHolder.queryNFT(args)
},
},
},