diff --git a/package.json b/package.json index 7409fb6..1ff2df2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/payload-mailing", - "version": "0.4.18", + "version": "0.4.19", "description": "Template-based email system with scheduling and job processing for PayloadCMS", "type": "module", "main": "dist/index.js", diff --git a/src/utils/jobScheduler.ts b/src/utils/jobScheduler.ts index 6d09751..cbfed6c 100644 --- a/src/utils/jobScheduler.ts +++ b/src/utils/jobScheduler.ts @@ -129,7 +129,11 @@ export async function updateEmailJobRelationship( id: normalizedEmailId, }) - const currentJobs = (currentEmail.jobs || []).map((job: any) => String(job)) + // Extract IDs from job objects or use the value directly if it's already an ID + // Jobs can be populated (objects with id field) or just IDs (strings/numbers) + const currentJobs = (currentEmail.jobs || []).map((job: any) => + typeof job === 'object' && job !== null && job.id ? String(job.id) : String(job) + ) const allJobs = [...new Set([...currentJobs, ...normalizedJobIds])] // Deduplicate with normalized strings await payload.update({