mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 08:13:23 +00:00
Migrate dev server from MongoDB to SQLite
- Replace mongooseAdapter with sqliteAdapter in payload config - Update database configuration to use file:./dev.db - Remove MongoDB memory database helper and references - Simplify start script by removing verbose logging and MongoDB messaging - Fix email processing with immediate send support and proper queue handling - Restructure app with route groups for frontend/admin separation - Add dashboard and test pages for email management - Update API routes for improved email processing and testing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,24 +4,25 @@ import config from '@payload-config'
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const payload = await getPayload({ config })
|
||||
|
||||
// Queue the combined email queue processing job
|
||||
const job = await payload.jobs.queue({
|
||||
task: 'process-email-queue',
|
||||
input: {},
|
||||
|
||||
// Run jobs in the default queue (the plugin already schedules email processing on init)
|
||||
const results = await payload.jobs.run({
|
||||
queue: 'default',
|
||||
})
|
||||
|
||||
|
||||
const processedCount = Array.isArray(results) ? results.length : (results ? 1 : 0)
|
||||
|
||||
return Response.json({
|
||||
success: true,
|
||||
message: 'Email queue processing job queued successfully (will process both pending and failed emails)',
|
||||
jobId: job.id,
|
||||
message: `Email queue processing completed. Processed ${processedCount} jobs.`,
|
||||
processedJobs: processedCount,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Process emails error:', error)
|
||||
return Response.json(
|
||||
{
|
||||
{
|
||||
error: 'Failed to process emails',
|
||||
details: error instanceof Error ? error.message : 'Unknown error'
|
||||
details: error instanceof Error ? error.message : 'Unknown error'
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getPayload } from 'payload'
|
||||
import config from '@payload-config'
|
||||
import { sendEmail } from '@xtr-dev/payload-mailing'
|
||||
import { sendEmail, processEmailById } from '@xtr-dev/payload-mailing'
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
@@ -41,10 +41,33 @@ export async function POST(request: Request) {
|
||||
|
||||
const result = await sendEmail(payload, emailOptions)
|
||||
|
||||
// If it's "send now" (not scheduled), process the email immediately
|
||||
if (type === 'send' && !scheduledAt) {
|
||||
try {
|
||||
await processEmailById(payload, String(result.id))
|
||||
return Response.json({
|
||||
success: true,
|
||||
emailId: result.id,
|
||||
message: 'Email sent successfully',
|
||||
status: 'sent'
|
||||
})
|
||||
} catch (processError) {
|
||||
// If immediate processing fails, return that it's queued
|
||||
console.warn('Failed to process email immediately, left in queue:', processError)
|
||||
return Response.json({
|
||||
success: true,
|
||||
emailId: result.id,
|
||||
message: 'Email queued successfully (immediate processing failed)',
|
||||
status: 'queued'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
success: true,
|
||||
emailId: result.id,
|
||||
message: scheduledAt ? 'Email scheduled successfully' : 'Email queued successfully',
|
||||
status: scheduledAt ? 'scheduled' : 'queued'
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Test email error:', error)
|
||||
|
||||
Reference in New Issue
Block a user