From 70fb79cca44b123c259c796d59b75f888b2b521a Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sun, 14 Sep 2025 20:41:19 +0200 Subject: [PATCH] Add has-many relationship from emails to processing jobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ New Feature: - Add 'jobs' relationship field to emails collection - Shows all PayloadCMS jobs associated with each email - Read-only field with smart filtering by emailId - Visible in admin interface for better email tracking 🔍 Benefits: - Track job status and history for each email - Debug processing issues more easily - Monitor job queue performance per email - Complete email processing visibility --- src/collections/Emails.ts | 20 +++++++++++++++++++- src/sendEmail.ts | 22 +++++++++++++++------- src/utils/emailProcessor.ts | 2 +- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/collections/Emails.ts b/src/collections/Emails.ts index d86ba6d..503f9aa 100644 --- a/src/collections/Emails.ts +++ b/src/collections/Emails.ts @@ -4,7 +4,7 @@ const Emails: CollectionConfig = { slug: 'emails', admin: { useAsTitle: 'subject', - defaultColumns: ['subject', 'to', 'status', 'scheduledAt', 'sentAt'], + defaultColumns: ['subject', 'to', 'status', 'jobs', 'scheduledAt', 'sentAt'], group: 'Mailing', description: 'Email delivery and status tracking', }, @@ -164,6 +164,24 @@ const Emails: CollectionConfig = { description: 'Email priority (1=highest, 10=lowest)', }, }, + { + name: 'jobs', + type: 'relationship', + relationTo: 'payload-jobs', + hasMany: true, + admin: { + description: 'Processing jobs associated with this email', + allowCreate: false, + readOnly: true, + }, + filterOptions: ({ id }) => { + return { + 'input.emailId': { + equals: id, + }, + } + }, + }, ], timestamps: true, // indexes: [ diff --git a/src/sendEmail.ts b/src/sendEmail.ts index 3b3cafd..d07f91a 100644 --- a/src/sendEmail.ts +++ b/src/sendEmail.ts @@ -168,13 +168,19 @@ export const sendEmail = async