@@ -349,7 +349,8 @@ export default class PostgresReviewDataSource implements ReviewDataSource {
349349 userId ?: number ,
350350 callId ?: number ,
351351 instrumentId ?: number ,
352- status ?: ReviewStatus
352+ status ?: ReviewStatus ,
353+ active ?: boolean
353354 ) : Promise < Review [ ] > {
354355 return database
355356 . select ( )
@@ -378,6 +379,16 @@ export default class PostgresReviewDataSource implements ReviewDataSource {
378379 if ( status !== undefined && status !== null ) {
379380 qb . where ( 'fap_reviews.status' , status ) ;
380381 }
382+
383+ if ( active ) {
384+ qb . join ( 'proposals' , {
385+ 'proposals.proposal_pk' : 'fap_reviews.proposal_pk' ,
386+ } ) ;
387+ qb . join ( 'call' , {
388+ 'call.call_id' : 'proposals.call_id' ,
389+ } ) ;
390+ qb . where ( 'call.call_fap_review_ended' , false ) ;
391+ }
381392 } )
382393 . whereIn ( 'fap_id' , fapIds )
383394 . distinctOn ( 'fap_reviews.proposal_pk' )
@@ -414,7 +425,8 @@ export default class PostgresReviewDataSource implements ReviewDataSource {
414425 userId ?: number ,
415426 callId ?: number ,
416427 instrumentId ?: number ,
417- status ?: ReviewStatus
428+ status ?: ReviewStatus ,
429+ active ?: boolean
418430 ) : Promise < Review [ ] > {
419431 return database
420432 . select ( 'fapReviewsTemp.*' )
@@ -440,6 +452,16 @@ export default class PostgresReviewDataSource implements ReviewDataSource {
440452 if ( status !== null && status !== undefined ) {
441453 qb . where ( 'fap_reviews.status' , status ) ;
442454 }
455+
456+ if ( active ) {
457+ qb . join ( 'proposals' , {
458+ 'proposals.proposal_pk' : 'fap_reviews.proposal_pk' ,
459+ } ) ;
460+ qb . join ( 'call' , {
461+ 'call.call_id' : 'proposals.call_id' ,
462+ } ) ;
463+ qb . where ( 'call.call_fap_review_ended' , false ) ;
464+ }
443465 } )
444466 . whereIn ( 'fap_id' , fapIds )
445467 . as ( 'fapReviewsTemp' )
0 commit comments