@@ -71,9 +71,7 @@ export class FindingsService {
7171 ] ,
7272 } ) ;
7373
74- this . logger . log (
75- `Retrieved ${ findings . length } findings for task ${ taskId } ` ,
76- ) ;
74+ this . logger . log ( `Retrieved ${ findings . length } findings for task ${ taskId } ` ) ;
7775 return findings ;
7876 }
7977
@@ -311,19 +309,38 @@ export class FindingsService {
311309 }
312310
313311 // ready_for_review can only be set by non-auditor admins/owners (client signals to auditor)
314- if ( updateDto . status === FindingStatus . ready_for_review && isAuditor && ! isPlatformAdmin ) {
312+ if (
313+ updateDto . status === FindingStatus . ready_for_review &&
314+ isAuditor &&
315+ ! isPlatformAdmin
316+ ) {
315317 throw new ForbiddenException (
316318 `Auditors cannot set status to 'ready_for_review'. This status is for clients to signal readiness.` ,
317319 ) ;
318320 }
319321 }
320322
323+ // Handle revisionNote logic:
324+ // - Set revisionNote when status is needs_revision and a note is provided
325+ // - Clear revisionNote when status changes to anything other than needs_revision
326+ let revisionNoteUpdate : { revisionNote ?: string | null } = { } ;
327+ if ( updateDto . status === FindingStatus . needs_revision ) {
328+ // Set revision note if provided (can be null to clear)
329+ if ( updateDto . revisionNote !== undefined ) {
330+ revisionNoteUpdate = { revisionNote : updateDto . revisionNote || null } ;
331+ }
332+ } else if ( updateDto . status !== undefined ) {
333+ // Clear revision note when moving to a different status
334+ revisionNoteUpdate = { revisionNote : null } ;
335+ }
336+
321337 const updatedFinding = await db . finding . update ( {
322338 where : { id : findingId } ,
323339 data : {
324340 ...( updateDto . status !== undefined && { status : updateDto . status } ) ,
325341 ...( updateDto . type !== undefined && { type : updateDto . type } ) ,
326342 ...( updateDto . content !== undefined && { content : updateDto . content } ) ,
343+ ...revisionNoteUpdate ,
327344 } ,
328345 include : {
329346 createdBy : {
@@ -411,22 +428,34 @@ export class FindingsService {
411428
412429 switch ( updateDto . status ) {
413430 case FindingStatus . ready_for_review :
414- this . logger . log ( `Triggering 'ready_for_review' notification for finding ${ findingId } ` ) ;
431+ this . logger . log (
432+ `Triggering 'ready_for_review' notification for finding ${ findingId } ` ,
433+ ) ;
415434 void this . findingNotifierService . notifyReadyForReview ( {
416435 ...notificationParams ,
417436 findingCreatorMemberId : finding . createdById ,
418437 } ) ;
419438 break ;
420439 case FindingStatus . needs_revision :
421- this . logger . log ( `Triggering 'needs_revision' notification for finding ${ findingId } ` ) ;
422- void this . findingNotifierService . notifyNeedsRevision ( notificationParams ) ;
440+ this . logger . log (
441+ `Triggering 'needs_revision' notification for finding ${ findingId } ` ,
442+ ) ;
443+ void this . findingNotifierService . notifyNeedsRevision (
444+ notificationParams ,
445+ ) ;
423446 break ;
424447 case FindingStatus . closed :
425- this . logger . log ( `Triggering 'closed' notification for finding ${ findingId } ` ) ;
426- void this . findingNotifierService . notifyFindingClosed ( notificationParams ) ;
448+ this . logger . log (
449+ `Triggering 'closed' notification for finding ${ findingId } ` ,
450+ ) ;
451+ void this . findingNotifierService . notifyFindingClosed (
452+ notificationParams ,
453+ ) ;
427454 break ;
428455 case FindingStatus . open :
429- this . logger . log ( `Status changed to 'open' for finding ${ findingId } . No notification sent.` ) ;
456+ this . logger . log (
457+ `Status changed to 'open' for finding ${ findingId } . No notification sent.` ,
458+ ) ;
430459 break ;
431460 default :
432461 this . logger . warn (
@@ -489,6 +518,9 @@ export class FindingsService {
489518 // Verify finding exists
490519 await this . findById ( organizationId , findingId ) ;
491520
492- return this . findingAuditService . getFindingActivity ( findingId , organizationId ) ;
521+ return this . findingAuditService . getFindingActivity (
522+ findingId ,
523+ organizationId ,
524+ ) ;
493525 }
494526}
0 commit comments