fix: add @types/nodemailer and include event links in RSVP email content

This commit is contained in:
Ryderjj89
2025-05-05 08:31:29 -04:00
parent c2b4217601
commit 7364e12c86
4 changed files with 15 additions and 2 deletions

View File

@@ -22,6 +22,7 @@
"@types/node": "^20.4.5", "@types/node": "^20.4.5",
"@types/cors": "^2.8.13", "@types/cors": "^2.8.13",
"@types/sqlite3": "^3.1.8", "@types/sqlite3": "^3.1.8",
"@types/nodemailer": "^6.4.12",
"typescript": "^5.1.6", "typescript": "^5.1.6",
"nodemon": "^3.0.1", "nodemon": "^3.0.1",
"ts-node": "^10.9.1" "ts-node": "^10.9.1"

View File

@@ -12,6 +12,7 @@ const transporter = nodemailer.createTransport({
export interface RSVPEmailData { export interface RSVPEmailData {
eventTitle: string; eventTitle: string;
eventSlug: string;
name: string; name: string;
attending: string; attending: string;
bringingGuests: string; bringingGuests: string;
@@ -25,6 +26,7 @@ export interface RSVPEmailData {
export async function sendRSVPEmail(data: RSVPEmailData) { export async function sendRSVPEmail(data: RSVPEmailData) {
const { const {
eventTitle, eventTitle,
eventSlug,
name, name,
attending, attending,
bringingGuests, bringingGuests,
@@ -40,6 +42,11 @@ export async function sendRSVPEmail(data: RSVPEmailData) {
const itemsList = itemsBringing.length ? itemsBringing.join(', ') : 'None'; const itemsList = itemsBringing.length ? itemsBringing.join(', ') : 'None';
const otherItemsList = otherItems ? otherItems : 'None'; const otherItemsList = otherItems ? otherItems : 'None';
// Assume the frontend is served at the same host
const baseUrl = process.env.FRONTEND_BASE_URL || '';
const manageRsvpsUrl = `${baseUrl}/events/${eventSlug}/manage-rsvps`;
const viewRsvpsUrl = `${baseUrl}/events/${eventSlug}/rsvps`;
const html = ` const html = `
<h2>RSVP Confirmation</h2> <h2>RSVP Confirmation</h2>
<p><strong>Event:</strong> ${eventTitle}</p> <p><strong>Event:</strong> ${eventTitle}</p>
@@ -49,6 +56,8 @@ export async function sendRSVPEmail(data: RSVPEmailData) {
<p><strong>Guest Names:</strong> ${guestList}</p> <p><strong>Guest Names:</strong> ${guestList}</p>
<p><strong>Items Bringing (from needed list):</strong> ${itemsList}</p> <p><strong>Items Bringing (from needed list):</strong> ${itemsList}</p>
<p><strong>Other Items:</strong> ${otherItemsList}</p> <p><strong>Other Items:</strong> ${otherItemsList}</p>
<p><a href="${manageRsvpsUrl}">Manage RSVPs for this event</a></p>
<p><a href="${viewRsvpsUrl}">View all RSVPs for this event</a></p>
`; `;
await transporter.sendMail({ await transporter.sendMail({

View File

@@ -295,15 +295,17 @@ app.post('/api/events/:slug/rsvp', async (req: Request, res: Response) => {
[eventId, name, attending, bringing_guests, guest_count, JSON.stringify(parsedGuestNames), JSON.stringify(parsedItemsBringing), other_items || ''] [eventId, name, attending, bringing_guests, guest_count, JSON.stringify(parsedGuestNames), JSON.stringify(parsedItemsBringing), other_items || '']
); );
// Fetch event title for the email // Fetch event title and slug for the email
const eventInfo = await db.get('SELECT title FROM events WHERE id = ?', [eventId]); const eventInfo = await db.get('SELECT title, slug FROM events WHERE id = ?', [eventId]);
const eventTitle = eventInfo ? eventInfo.title : slug; const eventTitle = eventInfo ? eventInfo.title : slug;
const eventSlug = eventInfo ? eventInfo.slug : slug;
// Send RSVP confirmation email (if email provided) // Send RSVP confirmation email (if email provided)
if (req.body.email) { if (req.body.email) {
try { try {
await sendRSVPEmail({ await sendRSVPEmail({
eventTitle, eventTitle,
eventSlug,
name, name,
attending, attending,
bringingGuests: bringing_guests, bringingGuests: bringing_guests,

View File

@@ -16,6 +16,7 @@ services:
- EMAIL_FROM_NAME=RSVP Manager - EMAIL_FROM_NAME=RSVP Manager
- EMAIL_FROM_ADDRESS=your@email.com - EMAIL_FROM_ADDRESS=your@email.com
- EMAIL_SECURE=false - EMAIL_SECURE=false
- FRONTEND_BASE_URL=https://your-frontend-domain.com
restart: unless-stopped restart: unless-stopped
volumes: volumes: