Skip to content

Commit 751d4c5

Browse files
org endpoints
1 parent 527b261 commit 751d4c5

2 files changed

Lines changed: 49 additions & 7 deletions

File tree

backend/controllers/notificationController.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ export const sendRejectionEmail = async (
124124
organizationName: string,
125125
reason?: string
126126
) => {
127+
console.log('[sendRejectionEmail] Starting email send to:', organizationEmail);
128+
console.log('[sendRejectionEmail] Organization name:', organizationName);
129+
console.log('[sendRejectionEmail] Reason:', reason);
130+
127131
const htmlBody = `
128132
<!DOCTYPE html>
129133
<html>
@@ -211,14 +215,20 @@ Tennessee Coalition for Better Aging
211215
ReplyToAddresses: [sesConfig.replyToEmail],
212216
});
213217

214-
await sesClient.send(command);
218+
console.log('[sendRejectionEmail] Sending email via AWS SES...');
219+
const result = await sesClient.send(command);
220+
console.log('[sendRejectionEmail] Email sent successfully! MessageId:', result.MessageId);
215221
};
216222

217223
export const sendDeletionEmail = async (
218224
organizationEmail: string,
219225
organizationName: string,
220226
reason?: string
221227
) => {
228+
console.log('[sendDeletionEmail] Starting email send to:', organizationEmail);
229+
console.log('[sendDeletionEmail] Organization name:', organizationName);
230+
console.log('[sendDeletionEmail] Reason:', reason);
231+
222232
const htmlBody = `
223233
<!DOCTYPE html>
224234
<html>
@@ -306,7 +316,9 @@ Tennessee Coalition for Better Aging
306316
ReplyToAddresses: [sesConfig.replyToEmail],
307317
});
308318

309-
await sesClient.send(command);
319+
console.log('[sendDeletionEmail] Sending email via AWS SES...');
320+
const result = await sesClient.send(command);
321+
console.log('[sendDeletionEmail] Email sent successfully! MessageId:', result.MessageId);
310322
};
311323

312324
export const sendCustomEmail = async (req: AuthenticatedRequest, res: Response) => {

backend/controllers/organizationController.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)