// Schedule reminders for recent appointments const { PrismaClient } = require('@prisma/client'); const prisma = new PrismaClient(); // Import the reminder scheduling function const { scheduleReminders, sendBookingConfirmation } = require('./src/lib/reminders.ts'); async function main() { console.log('šŸ“… Finding recent appointments...'); const appointments = await prisma.appointment.findMany({ where: { status: { in: ['scheduled', 'confirmed'] }, dateTime: { gte: new Date() } }, include: { clinic: true, lead: true, treatment: true }, orderBy: { createdAt: 'desc' }, take: 5 }); console.log(`Found ${appointments.length} appointments to schedule reminders for:`); for (const apt of appointments) { console.log(`šŸ“‹ ${apt.lead.name} - ${apt.treatment.name} on ${apt.dateTime}`); try { await scheduleReminders(apt.id); console.log(` āœ… Reminders scheduled`); // Send immediate booking confirmation await sendBookingConfirmation(apt.id); console.log(` šŸ“Ø Booking confirmation sent`); } catch (error) { console.log(` āŒ Error: ${error.message}`); } } // Check final reminder count const reminderCount = await prisma.scheduledReminder.count({ where: { status: 'pending' } }); console.log(`\nšŸ“Š Total pending reminders: ${reminderCount}`); await prisma.$disconnect(); } main().catch(console.error);