@@ -22,7 +22,6 @@ export function startVerificationJob() {
2222
2323 // Find all organisations with selected administrators
2424 const organisations = await Organisation . find ( {
25- 'Administrators.IsSelected' : true ,
2625 // TODO: remove this after testing
2726 DocumentCreationDate : { $gte : new Date ( '2025-11-01' ) }
2827 } ) ;
@@ -39,23 +38,24 @@ export function startVerificationJob() {
3938
4039 // Find selected administrator
4140 const selectedAdmin = org . Administrators . find ( admin => admin . IsSelected ) ;
41+ const email = selectedAdmin ?. Email || org . Email ;
4242
43- if ( ! selectedAdmin || ! selectedAdmin . Email ) {
43+ if ( ! email ) {
4444 continue ;
4545 }
4646
4747 // Check if exactly 90 days (send reminder)
4848 if ( daysSinceUpdate === 90 ) {
49- console . log ( `Reminder sent for: ${ org . Name } (${ selectedAdmin . Email } )` ) ;
49+ console . log ( `Reminder sent for: ${ org . Name } (${ email } )` ) ;
5050 const emailSent = await sendVerificationReminderEmail (
51- selectedAdmin . Email ,
51+ email ,
5252 org . Name ,
5353 daysSinceUpdate
5454 ) ;
5555
5656 if ( emailSent ) {
5757 remindersCount ++ ;
58- console . log ( `Reminder sent for: ${ org . Name } (${ selectedAdmin . Email } )` ) ;
58+ console . log ( `Reminder sent for: ${ org . Name } (${ email } )` ) ;
5959 } else {
6060 errors . push ( `Failed to send reminder for ${ org . Name } ` ) ;
6161 }
@@ -73,13 +73,13 @@ export function startVerificationJob() {
7373
7474 // Send notification email
7575 const emailSent = await sendVerificationExpiredEmail (
76- selectedAdmin . Email ,
76+ email ,
7777 org . Name
7878 ) ;
7979
8080 if ( emailSent ) {
8181 unverifiedCount ++ ;
82- console . log ( `Organisation unverified: ${ org . Name } (${ selectedAdmin . Email } )` ) ;
82+ console . log ( `Organisation unverified: ${ org . Name } (${ email } )` ) ;
8383 console . log ( ` - Related services updated: ${ totalUpdated } ` ) ;
8484 } else {
8585 errors . push ( `Failed to send expiration email for ${ org . Name } ` ) ;
0 commit comments