mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 08:13:23 +00:00
- Deleted batch email processing logic in favor of individual email jobs - Updated `mailingJobs` to only register `processEmailJob` - Simplified LiquidJS initialization check in `MailingService` - Bumped version to 0.4.13
72 lines
1.5 KiB
TypeScript
72 lines
1.5 KiB
TypeScript
import type { PayloadRequest } from 'payload'
|
|
import { processEmailById } from '../utils/emailProcessor.js'
|
|
|
|
/**
|
|
* Data passed to the individual email processing job
|
|
*/
|
|
export interface ProcessEmailJobInput {
|
|
/**
|
|
* The ID of the email to process
|
|
*/
|
|
emailId: string | number
|
|
}
|
|
|
|
/**
|
|
* Job definition for processing a single email
|
|
*/
|
|
export const processEmailJob = {
|
|
slug: 'process-email',
|
|
label: 'Process Individual Email',
|
|
inputSchema: [
|
|
{
|
|
name: 'emailId',
|
|
type: 'text' as const,
|
|
required: true,
|
|
label: 'Email ID',
|
|
admin: {
|
|
description: 'The ID of the email to process and send'
|
|
}
|
|
}
|
|
],
|
|
outputSchema: [
|
|
{
|
|
name: 'success',
|
|
type: 'checkbox' as const
|
|
},
|
|
{
|
|
name: 'emailId',
|
|
type: 'text' as const
|
|
},
|
|
{
|
|
name: 'status',
|
|
type: 'text' as const
|
|
}
|
|
],
|
|
handler: async ({ input, req }: { input: ProcessEmailJobInput; req: PayloadRequest }) => {
|
|
const payload = (req as any).payload
|
|
const { emailId } = input
|
|
|
|
if (!emailId) {
|
|
throw new Error('Email ID is required for processing')
|
|
}
|
|
|
|
try {
|
|
// Process the individual email
|
|
await processEmailById(payload, String(emailId))
|
|
|
|
return {
|
|
output: {
|
|
success: true,
|
|
emailId: String(emailId),
|
|
status: 'sent',
|
|
message: `Email ${emailId} processed successfully`
|
|
}
|
|
}
|
|
} catch (error) {
|
|
throw new Error(`Failed to process email ${emailId}: ${String(error)}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
export default processEmailJob
|