@@ -17,7 +17,7 @@ import { PublicKey } from "@solana/web3.js";
1717import { Op , QueryTypes } from "sequelize" ;
1818import { DAO } from "./constants" ;
1919import { Database , DeviceType , RewardableEntity } from "./database" ;
20- import { Reward , WalletClaimJob , sequelize } from "./model" ;
20+ import { KeyToAsset , Reward , WalletClaimJob , sequelize } from "./model" ;
2121
2222const ENTITY_CREATOR = entityCreatorKey ( DAO ) [ 0 ] ;
2323
@@ -212,6 +212,12 @@ export class PgDatabase implements Database {
212212 async getTotalRewards ( ) : Promise < string > {
213213 const totalRewards = (
214214 await Reward . findAll ( {
215+ include : [
216+ {
217+ model : KeyToAsset ,
218+ required : true ,
219+ } ,
220+ ] ,
215221 attributes : [
216222 [ sequelize . fn ( "SUM" , sequelize . col ( "rewards" ) ) , "rewards" ] ,
217223 ] ,
@@ -244,6 +250,12 @@ export class PgDatabase implements Database {
244250 async getBulkRewards ( entityKeys : string [ ] ) : Promise < Record < string , string > > {
245251 const rewards = await Reward . findAll ( {
246252 where : {
253+ include : [
254+ {
255+ model : KeyToAsset ,
256+ required : true ,
257+ } ,
258+ ] ,
247259 address : {
248260 [ Op . in ] : entityKeys ,
249261 } ,
@@ -289,7 +301,17 @@ export class PgDatabase implements Database {
289301 }
290302
291303 async getCurrentRewardsByEntity ( entityKeyStr : string ) {
292- const reward = ( await Reward . findByPk ( entityKeyStr ) ) as Reward ;
304+ const reward = ( await Reward . findOne ( {
305+ where : {
306+ address : entityKeyStr ,
307+ } ,
308+ include : [
309+ {
310+ model : KeyToAsset ,
311+ required : true ,
312+ } ,
313+ ] ,
314+ } ) ) as Reward ;
293315
294316 return new BN ( reward ?. rewards ) . toString ( ) || "0" ;
295317 }
0 commit comments