@@ -158,6 +158,18 @@ export const registerOrganization = async (req: AuthenticatedRequest, res: Respo
158158 } ) ;
159159 }
160160
161+ if ( ! primaryContactName || ! primaryContactEmail || ! primaryContactPhone ) {
162+ return res . status ( 400 ) . json ( {
163+ error : 'Primary contact information (name, email, phone) is required' ,
164+ } ) ;
165+ }
166+
167+ if ( ! organizationSize ) {
168+ return res . status ( 400 ) . json ( {
169+ error : 'Organization size is required' ,
170+ } ) ;
171+ }
172+
161173 const existingOrg = await prisma . organization . findFirst ( {
162174 where : { OR : [ { name } ] } ,
163175 } ) ;
@@ -218,7 +230,7 @@ export const registerOrganization = async (req: AuthenticatedRequest, res: Respo
218230 secondaryContactEmail : secondaryContactEmail || null ,
219231 region : region || null ,
220232 organizationType : organizationType || null ,
221- organizationSize : organizationSize || null ,
233+ organizationSize : organizationSize ,
222234 membershipActive : false ,
223235 membershipDate : null ,
224236 membershipRenewalDate : null ,
@@ -426,6 +438,8 @@ export const approveOrganization = async (req: AuthenticatedRequest, res: Respon
426438 status : 'ACTIVE' ,
427439 membershipActive : true ,
428440 membershipDate : new Date ( ) ,
441+ // Set default organizationSize if null (for legacy pending orgs)
442+ organizationSize : org . organizationSize || 'MEDIUM' ,
429443 } ,
430444 } ) ;
431445 try {
@@ -467,14 +481,22 @@ export const declineOrganization = async (req: AuthenticatedRequest, res: Respon
467481 return res . status ( 400 ) . json ( { error : 'Only pending organizations can be declined' } ) ;
468482 }
469483
484+ console . log ( '[DECLINE] Checking email addresses:' , {
485+ email : org . email ,
486+ primaryContactEmail : org . primaryContactEmail ,
487+ } ) ;
488+
470489 if ( org . email || org . primaryContactEmail ) {
471490 const recipientEmail = org . primaryContactEmail || org . email ;
491+ console . log ( '[DECLINE] Attempting to send rejection email to:' , recipientEmail ) ;
472492 try {
473493 await sendRejectionEmail ( recipientEmail , org . name , reason ) ;
474- console . log ( `Sent rejection notification to ${ recipientEmail } ` ) ;
494+ console . log ( `[DECLINE] SUCCESS - Sent rejection notification to ${ recipientEmail } ` ) ;
475495 } catch ( emailError ) {
476- console . error ( 'Error sending rejection email:' , emailError ) ;
496+ console . error ( '[DECLINE] ERROR - Failed to send rejection email:' , emailError ) ;
477497 }
498+ } else {
499+ console . log ( '[DECLINE] No email address found, skipping email notification' ) ;
478500 }
479501
480502 await prisma . organization . delete ( { where : { id } } ) ;
@@ -591,14 +613,22 @@ export const deleteOrganization = async (req: AuthenticatedRequest, res: Respons
591613 `Admin ${ req . user ?. id } is deleting organization ${ orgToDelete . name } (${ orgToDelete . id } )`
592614 ) ;
593615
616+ console . log ( '[DELETE] Checking email addresses:' , {
617+ email : orgToDelete . email ,
618+ primaryContactEmail : orgToDelete . primaryContactEmail ,
619+ } ) ;
620+
594621 if ( orgToDelete . email || orgToDelete . primaryContactEmail ) {
595622 const recipientEmail = orgToDelete . primaryContactEmail || orgToDelete . email ;
623+ console . log ( '[DELETE] Attempting to send deletion email to:' , recipientEmail ) ;
596624 try {
597625 await sendDeletionEmail ( recipientEmail , orgToDelete . name , reason ) ;
598- console . log ( `Sent deletion notification to ${ recipientEmail } ` ) ;
626+ console . log ( `[DELETE] SUCCESS - Sent deletion notification to ${ recipientEmail } ` ) ;
599627 } catch ( emailError ) {
600- console . error ( 'Error sending deletion email to organization :' , emailError ) ;
628+ console . error ( '[DELETE] ERROR - Failed to send deletion email :' , emailError ) ;
601629 }
630+ } else {
631+ console . log ( '[DELETE] No email address found, skipping email notification' ) ;
602632 }
603633
604634 const admins = await prisma . organization . findMany ( {
0 commit comments