From 20afe30e88c5b462ce32adc32ce13d2b62fb5a6f Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 23:53:25 +0200 Subject: [PATCH] Fix scheduledAt type in SendEmailTaskInput and add Date normalization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update SendEmailTaskInput.scheduledAt to support string | Date types - Add Date object normalization to ISO strings in sendEmail processing - Ensure consistent database storage format for all timestamp fields - Convert Date objects to ISO strings before database operations Resolves remaining "Type Date is not assignable to type string" error for scheduledAt field in job task input. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/jobs/sendEmailTask.ts | 2 +- src/sendEmail.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/jobs/sendEmailTask.ts b/src/jobs/sendEmailTask.ts index 77ed254..45b254e 100644 --- a/src/jobs/sendEmailTask.ts +++ b/src/jobs/sendEmailTask.ts @@ -15,7 +15,7 @@ export interface SendEmailTaskInput { to: string | string[] cc?: string | string[] bcc?: string | string[] - scheduledAt?: string // ISO date string + scheduledAt?: string | Date // ISO date string or Date object priority?: number // Allow any additional fields that users might have in their email collection diff --git a/src/sendEmail.ts b/src/sendEmail.ts index 6ca74f5..91cca46 100644 --- a/src/sendEmail.ts +++ b/src/sendEmail.ts @@ -100,6 +100,23 @@ export const sendEmail = async 0 ? validated[0] : undefined } + // Normalize Date objects to ISO strings for consistent database storage + if (emailData.scheduledAt instanceof Date) { + emailData.scheduledAt = emailData.scheduledAt.toISOString() + } + if (emailData.sentAt instanceof Date) { + emailData.sentAt = emailData.sentAt.toISOString() + } + if (emailData.lastAttemptAt instanceof Date) { + emailData.lastAttemptAt = emailData.lastAttemptAt.toISOString() + } + if (emailData.createdAt instanceof Date) { + emailData.createdAt = emailData.createdAt.toISOString() + } + if (emailData.updatedAt instanceof Date) { + emailData.updatedAt = emailData.updatedAt.toISOString() + } + // Create the email in the collection with proper typing const email = await payload.create({ collection: collectionSlug,