@@ -62,16 +62,16 @@ export class ReportsService {
6262
6363 try {
6464 const expressionAttributeValues : any = { ':userId' : userId } ;
65- let filterExpression = '' ;
65+ const processingStatusFilter = 'processingStatus <> :failedStatus ' ;
6666
6767 if ( ! withFailed ) {
68- filterExpression = ' AND processingStatus <> :failedStatus' ;
6968 expressionAttributeValues [ ':failedStatus' ] = ProcessingStatus . FAILED ;
7069 }
7170
7271 const command = new QueryCommand ( {
7372 TableName : this . tableName ,
74- KeyConditionExpression : 'userId = :userId' + filterExpression ,
73+ KeyConditionExpression : 'userId = :userId' ,
74+ FilterExpression : ! withFailed ? processingStatusFilter : undefined ,
7575 ExpressionAttributeValues : marshall ( expressionAttributeValues ) ,
7676 } ) ;
7777
@@ -116,17 +116,17 @@ export class ReportsService {
116116 const expressionAttributeValues : any = { ':userId' : userId } ;
117117
118118 try {
119- let filterExpression = '' ;
119+ const processingStatusFilter = 'processingStatus <> :failedStatus ' ;
120120
121121 if ( ! withFailed ) {
122- filterExpression = ' AND processingStatus <> :failedStatus' ;
123122 expressionAttributeValues [ ':failedStatus' ] = ProcessingStatus . FAILED ;
124123 }
125124
126125 const command = new QueryCommand ( {
127126 TableName : this . tableName ,
128127 IndexName : 'userIdCreatedAtIndex' ,
129- KeyConditionExpression : 'userId = :userId' + filterExpression ,
128+ KeyConditionExpression : 'userId = :userId' ,
129+ FilterExpression : ! withFailed ? processingStatusFilter : undefined ,
130130 ExpressionAttributeValues : marshall ( expressionAttributeValues ) ,
131131 ScanIndexForward : false ,
132132 Limit : limit ,
0 commit comments