@@ -10,7 +10,7 @@ import {BOUNTY_STATE_CHANGED} from "../integrations/telegram/messages";
1010import { Push } from "../services/analytics/push" ;
1111import { AnalyticEventName } from "../services/analytics/types/events" ;
1212import updateSeoCardBounty from "src/modules/handle-seo-card" ;
13- import { Op } from "sequelize" ;
13+ import { Op , Sequelize } from "sequelize" ;
1414
1515export const name = "getBountyPullRequestReadyForReviewEvents" ;
1616export const schedule = "*/12 * * * *" ;
@@ -22,7 +22,6 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
2222
2323 const { returnValues : { bountyId, pullRequestId} , connection, address, chainId} = block ;
2424
25-
2625 const bounty = await getBountyFromChain ( connection , address , bountyId , name ) ;
2726 if ( ! bounty )
2827 return eventsProcessed ;
@@ -42,25 +41,23 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
4241 return eventsProcessed ;
4342 }
4443
45-
4644 const pullRequest = bounty . pullRequests [ pullRequestId ] ;
4745
4846 const dbDeliverable = await db . deliverables . findOne ( {
49- where : { id : pullRequest . cid } ,
47+ where : { id : pullRequest . cid , markedReadyForReview : false } ,
5048 include : { association : 'user' }
51- } )
49+ } ) ;
5250
5351 if ( ! dbDeliverable ) {
5452 logger . warn ( `${ name } No deliverable found with "draft" and id ${ pullRequest . cid } , maybe it was already parsed?` ) ;
5553 return eventsProcessed ;
5654 }
5755
58- dbDeliverable . canceled = pullRequest . canceled
59- dbDeliverable . markedReadyForReview = pullRequest ?. ready
56+ dbDeliverable . canceled = pullRequest . canceled ;
57+ dbDeliverable . markedReadyForReview = pullRequest ?. ready ;
6058
6159 await dbDeliverable . save ( ) ;
6260
63-
6461 if ( ! [ "canceled" , "closed" , "proposal" ] . includes ( dbBounty . state ! ) ) {
6562 dbBounty . state = "ready" ;
6663 await dbBounty . save ( ) ;
@@ -77,12 +74,29 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
7774 ( async ( ) => {
7875 const owner = await dbBounty ! . getUser ( { attributes : [ "email" , "id" ] , include :[ { association : "user_settings" } ] } ) ;
7976
80- const curators = await dbBounty ! . network . getCurators ( {
81- include : [ { association : "user" , attributes : [ "email" , "id" ] , include :[ { association : "user_settings" } ] } ] ,
82- where : { userId : { [ Op . not ] : owner . id } , isCurrentlyCurator : true }
77+ const curators = await db . curators . findAll ( {
78+ include : [
79+ {
80+ association : "user" ,
81+ required : true ,
82+ attributes : [ "email" , "id" ] ,
83+ where : {
84+ id : {
85+ [ Op . not ] : owner . id
86+ } ,
87+ } ,
88+ on : Sequelize . where ( Sequelize . fn ( "lower" , Sequelize . col ( "curators.address" ) ) ,
89+ "=" ,
90+ Sequelize . fn ( "lower" , Sequelize . col ( "user.address" ) ) ) ,
91+ }
92+ ] ,
93+ where : {
94+ networkId : dbBounty . network_id ,
95+ isCurrentlyCurator : true
96+ }
8397 } ) ;
8498
85- const targets = curators . map ( curators => curators . user . get ( ) )
99+ const targets = curators . map ( curators => curators . user ) ;
86100
87101 const AnalyticEvent = {
88102 name : AnalyticEventName . PULL_REQUEST_READY ,
@@ -92,12 +106,13 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
92106 deliverableId : dbDeliverable . id , deliverableContractId : pullRequestId ,
93107 actor : pullRequest . creator ,
94108 }
95- }
109+ } ;
96110
97111 const NotificationEvent = {
98112 name : AnalyticEventName . NOTIF_DELIVERABLE_READY ,
99113 params : {
100114 targets : [ ...targets , owner ] ,
115+ bountyId : dbBounty . id ,
101116 creator : {
102117 address : dbDeliverable . user . address ,
103118 id : dbDeliverable . user . id ,
@@ -114,9 +129,9 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
114129 link : `${ dbBounty . network . name } /task/${ dbBounty . id } /deliverable/${ dbDeliverable . id } `
115130 }
116131 }
117- }
132+ } ;
118133
119- Push . events ( [ AnalyticEvent , NotificationEvent ] )
134+ Push . events ( [ AnalyticEvent , NotificationEvent ] ) ;
120135 } ) ( )
121136
122137
0 commit comments