add user totalSales and totalOrders (#333)

This commit is contained in:
Alex Coseru 2022-02-17 17:22:02 +02:00 committed by GitHub
parent cd27a2432d
commit dfb59ae6fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -281,6 +281,12 @@ type User @entity {
poolTransactions: [PoolTransaction!] @derivedFrom(field: "user")
orders: [Order!] @derivedFrom(field: "payer")
freSwaps: [FixedRateExchangeSwap!] @derivedFrom(field: "by")
"total number of orders made by this user"
totalOrders: BigInt!
"total number of orders made on assets owned by this user"
totalSales: BigInt!
}
type FixedRateExchange @entity {

View File

@ -38,6 +38,8 @@ export function handleOrderStarted(event: OrderStarted): void {
order.consumer = consumer.id
const payer = getUser(event.params.payer.toHex())
payer.totalOrders = payer.totalOrders.plus(integer.ONE)
payer.save()
order.payer = payer.id
order.amount = weiToDecimal(
@ -66,6 +68,9 @@ export function handleOrderStarted(event: OrderStarted): void {
nft.orderCount = nft.orderCount.plus(integer.ONE)
nft.save()
}
const owner = getUser(nft.owner)
owner.totalSales = owner.totalSales.plus(integer.ONE)
owner.save()
}
}